On start playing audio event

Hello here is my code:
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
})
const player = createAudioPlayer();
const resource = createAudioResource(
"MP3 URL",
{
metadata: {
title: "A good song", // Optional object
},
}
);

player.play(resource);
connection.subscribe(player);
player.on(AudioPlayerStatus.Playing, () => {
console.log("Start Playing")

});
const connection = joinVoiceChannel({
channelId: voiceChannel.id,
guildId: voiceChannel.guild.id,
adapterCreator: voiceChannel.guild.voiceAdapterCreator,
})
const player = createAudioPlayer();
const resource = createAudioResource(
"MP3 URL",
{
metadata: {
title: "A good song", // Optional object
},
}
);

player.play(resource);
connection.subscribe(player);
player.on(AudioPlayerStatus.Playing, () => {
console.log("Start Playing")

});
but the playing audio event, Logs this messages twice and when the second logging was sent into the console the bot start playing the audio
2 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
Python
PythonOP7mo ago
And i use the version 0.16.1 with node.js v21 No I was joined the voice channel and then i used this command But when i added player.play(resource) and connection.subsrcibe(player) to the VoiceConnectionStatusReady event in the connection.on(), actually the start playing audio event send a log once and exactly works for me Like this code:
connection.on(VoiceConnectionStatus.Ready, () => {
connection.subscribe(player);
player.play(resource);
});
connection.on(VoiceConnectionStatus.Ready, () => {
connection.subscribe(player);
player.play(resource);
});
What I meant by sending the log twice was that the first time it was actually doing it before the audio was played, but the second time it was exactly at the same time as the playing audio. And also the code above caused that first unrelated log to not be sent anymore But I can't understand why this way solved the problem and also are there any better ways?
Want results from more Discord servers?
Add your server