Hey everyone I’m having trouble with my Discord bot. I made it with DiscordJS and I want it to play YouTube videos when you type ‘!music’ plus a video link. But now it’s not working at all. I’ve tried fixing it many times but no luck. The rest of the bot is fine it’s just the music part that’s broken. Here’s my code:
I’ve encountered similar issues with DiscordJS audio. The problem might be related to outdated dependencies or incompatible audio libraries. Have you considered using the @discordjs/voice package? It’s specifically designed for voice connections and audio playback in Discord.js v13+.
Here’s a simplified example of how you could implement it:
I ran into a similar issue when building my music bot. From your code, it looks like you’re using some outdated or non-standard audio libraries. I’d recommend switching to the discord-player package - it’s much more reliable and easier to work with for audio streaming.
Here’s a basic setup that worked for me:
const { Player } = require('discord-player');
const player = new Player(client);
client.on('messageCreate', async (message) => {
if (message.content.startsWith('!play')) {
const query = message.content.split(' ')[1];
const queue = player.createQueue(message.guild, {
metadata: message.channel
});
try {
if (!queue.connection) await queue.connect(message.member.voice.channel);
} catch {
queue.destroy();
return await message.reply('Could not join your voice channel!');
}
const track = await player.search(query, {
requestedBy: message.user
}).then(x => x.tracks[0]);
if (!track) return await message.reply('Track not found!');
queue.play(track);
return await message.reply(`Loading track **${track.title}**!`);
}
});
This approach has been much more stable for me. Remember to install discord-player and its dependencies. Hope this helps!