Audio Player state changes to playing when resource ends

I am creating an audio resource from a ytdl download, and when I play this resource on the player with player.play(resource)the players state is set to "buffering", once the resource stops playing in the voice channel the players state changes to "playing". I am listening for when the player goes idle to queue the next song, however it never goes idle. My code is below:
const audio = ytdl(song, { filter: 'audioonly' });
const connection = joinVoiceChannel({
guildId: interaction.guild?.id!,
channelId: member.voice.channel.id,
adapterCreator: interaction.guild?.voiceAdapterCreator!
});
const player = createAudioPlayer();
connection.subscribe(player);
const resource = createAudioResource(audio);
const newQueue = new Queue(meta, player, resource);
client.queues.set(interaction.guild?.id!, newQueue);
const audio = ytdl(song, { filter: 'audioonly' });
const connection = joinVoiceChannel({
guildId: interaction.guild?.id!,
channelId: member.voice.channel.id,
adapterCreator: interaction.guild?.voiceAdapterCreator!
});
const player = createAudioPlayer();
connection.subscribe(player);
const resource = createAudioResource(audio);
const newQueue = new Queue(meta, player, resource);
client.queues.set(interaction.guild?.id!, newQueue);
Queue:
this.info = info;
this.player = player;
this.resource = resource;

this.player.play(resource);

this.player.on('stateChange', (state) => {
console.log(state.status);
if (state.status !== AudioPlayerStatus.Idle) return;
if (!this.songs[0]) return;
const song = ytdl(this.songs[0].videoDetails.video_url, { filter: 'audioonly' });
const newResource = createAudioResource(song);
this.resource = newResource;
this.player.play(newResource);
this.songs.shift();
});
this.info = info;
this.player = player;
this.resource = resource;

this.player.play(resource);

this.player.on('stateChange', (state) => {
console.log(state.status);
if (state.status !== AudioPlayerStatus.Idle) return;
if (!this.songs[0]) return;
const song = ytdl(this.songs[0].videoDetails.video_url, { filter: 'audioonly' });
const newResource = createAudioResource(song);
this.resource = newResource;
this.player.play(newResource);
this.songs.shift();
});
3 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Fallen
FallenOP2y ago
Discord.js: 14.8.0 @discordjs/voice: 0.16.0
bert
bert4d ago
I get this problem too could you please answer the question?
Want results from more Discord servers?
Add your server