Hey everyone! I’m new to making Discord bots and I’m stuck with a problem. I made a music bot that should play YouTube audio, but it’s not working right. The bot joins the voice channel when I use the command, but there’s no sound at all. Here’s my code:
I’ve dealt with this issue before, and it can be frustrating. One thing to check is your ffmpeg installation. Make sure it’s properly installed and accessible in your system’s PATH. Also, try adding a ‘ready’ event listener to your audioPlayer:
This will help you catch any playback errors. Additionally, consider using a try-catch block around the ytdl function call, as it can sometimes throw errors silently. If all else fails, you might want to explore alternative libraries like discord-player or discord-music-player, which can simplify the audio playback process significantly.
hey alexj, welcome to bot dev! looks like ur using ytdl-core-discord, but its kinda outdated. try switching to play-dl instead. it works way better with discord.js v14. also, make sure ur discord.js and @discordjs/voice packages r up to date. that might solve ur audio issues. good luck!
I’ve encountered similar issues when working with Discord bots and YouTube audio. From my experience, the problem might be related to how you’re handling the audio stream. Instead of using ytdl directly, try wrapping it in a demuxProbe() function from @discordjs/voice. Here’s a snippet that worked for me:
This approach helped me get the audio playing correctly. Also, double-check your bot’s permissions in the server to ensure it can connect and speak in voice channels. Hope this helps you get your bot singing!