.nerowo.
.nerowo.
DIAdiscord.js - Imagine an app
Created by .nerowo. on 8/14/2023 in #djs-voice
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
5 replies