YTDL AudioPlayer.play gives error

Hello! Trying to replicate a pseudo music bot from links with YTDL The bot enters in channel, but then returns the error: Error: Cannot play a resource that has already ended. Code:
var connection = voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});

const ap = voice.createAudioPlayer();
const song = await ytdl.getBasicInfo(args[1])

const stream = ytdl(song.url, {filter: 'audioonly'});
const resource = await voice.createAudioResource(stream, { inlineVolume: true })
// console.log(stream, resource, song.url)
const subs = await connection.subscribe(ap)
ap.play(resource)
var connection = voice.joinVoiceChannel({
channelId: voiceChannel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});

const ap = voice.createAudioPlayer();
const song = await ytdl.getBasicInfo(args[1])

const stream = ytdl(song.url, {filter: 'audioonly'});
const resource = await voice.createAudioResource(stream, { inlineVolume: true })
// console.log(stream, resource, song.url)
const subs = await connection.subscribe(ap)
ap.play(resource)
I've the GuildVoiceStates intent Then if i try without the ytdl.getbasic info, but directly with const song = args[1] // that is const args = message.content.split(" ");; i got a big long error: https://pastebin.com/VCLNcJ51
Pastebin
PlayerSubscription { connection: VoiceConnection { _ev - Past...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
1 Reply
d.js toolkit
d.js toolkit3mo ago
- What are your intents? GuildVoiceStates is required to receive voice data! - Show what dependencies you are using -- generateDependencyReport() is exported from @discordjs/voice. - Try looking at common examples: https://github.com/discordjs/voice-examples. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Want results from more Discord servers?
Add your server