Hello, have an issue: Discord bot with Discord.js v14.9.0. The bot is able to run sounds through voice channel either locally .mp3 files stored on the file system and YouTube videos as audio only. Problem is everything works fine till a request of sound through YouTube is received. The .mp3 sound commands no longer work the bot just remains silent till it is restarted. Sound with ytdl still work, though. Of course we want it to run MP3 files again without having to restart the bot.
This is my code:
#ytdl-core sound stream causes the bot to go permanently silent
9 messages · Page 1 of 1 (latest)
• 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.
This is my code:
/**
* Joins a voice channel and plays a sound.
* @param { Object } interaction Discord JS Client message or interaction property.
* @param { String } soundAsset Sound asset URL or path.
* @param { Boolean } useytdlModule Whether the sound asset is a YouTube URL or not.
* @param { Boolean } alert_voice_channel Bot will answer back that you need to be
* inside a voice channel.
*/
c.VoiceChannelJoinAndPlay = async (
interaction,
soundAsset,
{
volume = 1.0,
useytdlModule = true,
alert_voice_channel = false,
customErrorMessage = null
} = {}) => {
try {
// Joins the voice channel.
const connection = await joinVoiceChannel({
channelId: interaction.member.voice.channelId,
guildId: interaction.guild.id,
adapterCreator: interaction.guild.voiceAdapterCreator
});
// Sets resource object.
let resource = null;
if (useytdlModule === true) {
const _ytdl = ytdl(soundAsset, {
filter: 'audioonly',
quality: 'highestaudio'
});
resource = createAudioResource(_ytdl, { inlineVolume: true });
} else if (useytdlModule === false) {
resource = createAudioResource(soundAsset, { inlineVolume: true });
}
resource.volume.setVolume(volume);
// Sets player object, subscription and plays the sound.
const player = createAudioPlayer(resource);
connection.subscribe(player);
player.play(resource);
} catch (error) {
if (alert_voice_channel === true)
return customErrorMessage ?? 'Enter a voice channel.';
}
};
"dependencies": {
"@discordjs/opus": "0.9.0",
"@discordjs/voice": "0.16.0",
"discord.js": "14.9.0",
"opusscript": "0.0.8",
"sodium-native": "4.0.1",
"ytdl-core": "4.11.4"
},
I've tried to disconnect bot from voice channel but does not work. Only way to make it work again is restarting NodeJS completely. It is like there's still some kind of stream saved into the voice resource (createAudioResource object) still has some kind of reference. I've tried to unsubscribe from the current player as well.
NodeJs version: v16.17.0 (will update to 18.16.0 right now) Update: did not work
Fixed by installing ytdl-core-discord instead of ytdl-core
Wait that’s a package??
Does it change anything specific?
Or is it just a wrapper for the wrapper 💀