Bot isn't playing any Sound

Hey! I'm working for a games company and got tasked to create a discord bot that plays our ambient music in a voice channel. I'm using discord.js 14.12.1 and the bot itself works correctly and also joins the voice channel as it should. But it somehow doesn't play any audio. We're using local .mp3 files. Here's the code part for the AudioPlayer
const { joinVoiceChannel, createAudioResource, createAudioPlayer, generateDependencyReport, AudioPlayerStatus, VoiceConnectionStatus } = require('@discordjs/voice');

const player = createAudioPlayer();
const resource = createAudioResource('MusicFile.mp3');
player.play(resource);
voiceConnection.subscribe(player);
const { joinVoiceChannel, createAudioResource, createAudioPlayer, generateDependencyReport, AudioPlayerStatus, VoiceConnectionStatus } = require('@discordjs/voice');

const player = createAudioPlayer();
const resource = createAudioResource('MusicFile.mp3');
player.play(resource);
voiceConnection.subscribe(player);
I've also added some logs but apparently it's always "playing"
player.on(AudioPlayerStatus.Playing, () => {
console.log('The audio player has started playing!');
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('The audio player is idle.');
});

player.on('error', (error) => {
console.error('Audio player error:', error);
});

voiceConnection.on(VoiceConnectionStatus.Ready, () => {
console.log('Voice connection established successfully.');
});

voiceConnection.on(VoiceConnectionStatus.Disconnected, (oldState, newState) => {
console.log('Voice connection disconnected.');
player.stop();
voiceConnection.destroy();
});
player.on(AudioPlayerStatus.Playing, () => {
console.log('The audio player has started playing!');
});

player.on(AudioPlayerStatus.Idle, () => {
console.log('The audio player is idle.');
});

player.on('error', (error) => {
console.error('Audio player error:', error);
});

voiceConnection.on(VoiceConnectionStatus.Ready, () => {
console.log('Voice connection established successfully.');
});

voiceConnection.on(VoiceConnectionStatus.Disconnected, (oldState, newState) => {
console.log('Voice connection disconnected.');
player.stop();
voiceConnection.destroy();
});
And here's the Dependecy Report
Core Dependencies
- @discordjs/voice: 0.16.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: 0.7.11
- tweetnacl: not found

FFmpeg
- version: 5.0.1-essentials_build-www.gyan.dev
- libopus: yes
Core Dependencies
- @discordjs/voice: 0.16.0
- prism-media: 1.3.5

Opus Libraries
- @discordjs/opus: 0.9.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: 0.7.11
- tweetnacl: not found

FFmpeg
- version: 5.0.1-essentials_build-www.gyan.dev
- libopus: yes
4 Replies
d.js toolkit
d.js toolkit16mo 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!
.nerowo.
.nerowo.OP16mo ago
Thank you for your quick reply! I tried both methods but it still won't play any audio sadly. I even tried to follow this but that also didn't work (https://discordjs.guide/voice/audio-resources.html#creation) Could there be some other issues?
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
d.js docs
d.js docs16mo ago
To debug your voice connection and player: - Use debug: true when creating your VoiceConnection and AudioPlayer - Add an event listener to the <VoiceConnection> and the <AudioPlayer>:
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
// Add one for each class if applicable
<AudioPlayer | VoiceConnection>
.on('debug', console.log)
.on('error', console.error)
- Add an error listener to the stream you are passing to the resource:
<Stream>.on('error', console.error)
<Stream>.on('error', console.error)
Note: The <> represents classes that need to be adapted to their respective name in your code
.nerowo.
.nerowo.OP16mo ago
I managed to fix it now after some struggles. I forgot to set the GuildVoiceStates gateway intent.
Want results from more Discord servers?
Add your server