I’m working on a Discord bot using discord.js v13 and trying to get it to play MP3 files in voice channels. The bot connects to the voice channel successfully but no audio plays at all.
const voiceConnection = joinVoiceChannel({
channelId: userVoice.channelId,
guildId: message.guildId,
adapterCreator: userVoice.channel.guild.voiceAdapterCreator,
});
const audioFile = createAudioResource(createReadStream(join(__dirname, 'sounds/music.mp3')), {
inlineVolume: true
});
audioFile.volume.setVolume(0.3);
const musicPlayer = createAudioPlayer();
voiceConnection.subscribe(musicPlayer);
musicPlayer.play(audioFile);
console.log('Audio should be playing now');
await message.reply('Bot has joined and should be playing music!');
I verified the file path is correct and checked my dependencies. All required libraries seem to be installed properly. The bot joins the channel but stays silent. What could be causing this audio playback problem?
sounds like ur missing the ffmpeg dependency mate. discord.js v13 needs ffmpeg to process audio files properly. make sure you have it installed on your system or try using @discordjs/opus package too for better performance
Check if your voice connection is actually ready before trying to play audio. I encountered similar silence issues and discovered the connection state wasn’t fully established. Add voiceConnection.on(VoiceConnectionStatus.Ready, () => { /* play audio here */ }) to ensure the connection is stable before starting playback. Also verify your bot has the correct permissions in the voice channel - specifically “Connect”, “Speak”, and “Use Voice Activity”. Without proper permissions the bot can join but won’t transmit audio. Try moving your musicPlayer.play() call inside the Ready event handler and see if that resolves the silent playback issue.
Had this exact same issue a few months back and it drove me crazy for hours. The problem is likely that you’re not handling the audio player events properly. Your code looks fine but you need to listen for the player state changes to catch any errors. Try adding musicPlayer.on('error', error => console.error(error)) and musicPlayer.on(AudioPlayerStatus.Idle, () => console.log('finished playing')) before calling play(). Also make sure your MP3 file isn’t corrupted by testing it with a simple WAV file first. Sometimes the issue is just the audio format even though MP3 should work fine with proper ffmpeg setup.