Mp3 audio not playing

Hello i followed various guides and threads in this server to create a command !play that enables the bot to stream an mp3 file located in his folder. The bot joins the channel but the audio don't start, no errors in the terminal. [email protected] Node v16.20.2 @discordjs/[email protected] @discordjs/[email protected]
const { entersState, joinVoiceChannel, VoiceConnectionStatus, EndBehaviorType, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const ffmpeg = require('ffmpeg-static');

client.on('messageCreate', async (message) => {
if (message.content === '!play') {
if (!message.member.voice?.channel) return message.channel.send('You need to be a voice channel to execute this command')

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guildId,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer()
const resource = createAudioResource('./music/song.mp3')

connection.subscribe(player)

player.play(resource)
}
})
const { entersState, joinVoiceChannel, VoiceConnectionStatus, EndBehaviorType, createAudioPlayer, createAudioResource, AudioPlayerStatus } = require('@discordjs/voice');
const ffmpeg = require('ffmpeg-static');

client.on('messageCreate', async (message) => {
if (message.content === '!play') {
if (!message.member.voice?.channel) return message.channel.send('You need to be a voice channel to execute this command')

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guildId,
adapterCreator: message.guild.voiceAdapterCreator
})

const player = createAudioPlayer()
const resource = createAudioResource('./music/song.mp3')

connection.subscribe(player)

player.play(resource)
}
})
14 Replies
d.js toolkit
d.js toolkit4mo 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!
duck
duck4mo ago
first before debugging, please try updating @discordjs/voice latest version is 0.17.0 0.7.5 is a little outdated
d.js docs
d.js docs4mo 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
Tommy
TommyOP4mo ago
thank you, no changes updating voice. here the debug results:
state change:
from {"status":"idle","resource":false,"stepTimeout":false}
to {"status":"buffering","resource":true,"stepTimeout":false}
state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
state change:
from {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
to {"status":"autopaused","missedFrames":0,"playbackDuration":0,"resource":true,"silencePacketsRemaining":5,"stepTimeout":false}
[NW] [WS] >> {"op":0,"d":{"server_id":"792382153945514004","user_id":"1157789261639196804","session_id":"30edb2134b9b1631fdf0b53e4b3a3130","token":"3fe376480b871a94"}}
[NW] state change:
from {"code":0,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
to {"code":1,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
[NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}
[NW] [WS] << {"op":2,"d":{"streams":[{"type":"video","ssrc":22191,"rtx_ssrc":22192,"rid":"","quality":0,"active":false}],"ssrc":22190,"port":50025,"modes":["aead_aes256_gcm_rtpsize","aead_aes256_gcm","aead_xchacha20_poly1305_rtpsize","xsalsa20_poly1305_lite_rtpsize","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"66.22.243.139","experiments":["fixed_keyframe_interval"]}}
[NW] state change:
from {"code":1,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
to {"code":2,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":true,"connectionData":{"ssrc":22190}}
[NW] [WS] << {"op":11,"d":{"user_ids":["469522996277674004"]}}
[NW] [WS] << {"op":18,"d":{"user_id":"469522996277674004","flags":2}}
[NW] [WS] << {"op":20,"d":{"user_id":"469522996277674004","platform":0}}
[NW] state change:
from {"code":2,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":true,"connectionData":{"ssrc":22190}}
to {"code":6,"ws":false,"udp":false}
state change:
from {"status":"idle","resource":false,"stepTimeout":false}
to {"status":"buffering","resource":true,"stepTimeout":false}
state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
state change:
from {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
to {"status":"autopaused","missedFrames":0,"playbackDuration":0,"resource":true,"silencePacketsRemaining":5,"stepTimeout":false}
[NW] [WS] >> {"op":0,"d":{"server_id":"792382153945514004","user_id":"1157789261639196804","session_id":"30edb2134b9b1631fdf0b53e4b3a3130","token":"3fe376480b871a94"}}
[NW] state change:
from {"code":0,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
to {"code":1,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
[NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}
[NW] [WS] << {"op":2,"d":{"streams":[{"type":"video","ssrc":22191,"rtx_ssrc":22192,"rid":"","quality":0,"active":false}],"ssrc":22190,"port":50025,"modes":["aead_aes256_gcm_rtpsize","aead_aes256_gcm","aead_xchacha20_poly1305_rtpsize","xsalsa20_poly1305_lite_rtpsize","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"66.22.243.139","experiments":["fixed_keyframe_interval"]}}
[NW] state change:
from {"code":1,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":false}
to {"code":2,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":true,"connectionData":{"ssrc":22190}}
[NW] [WS] << {"op":11,"d":{"user_ids":["469522996277674004"]}}
[NW] [WS] << {"op":18,"d":{"user_id":"469522996277674004","flags":2}}
[NW] [WS] << {"op":20,"d":{"user_id":"469522996277674004","platform":0}}
[NW] state change:
from {"code":2,"ws":true,"connectionOptions":{"endpoint":"frankfurt9970.discord.media:443","serverId":"792382153945514004","token":"3fe376480b871a94","sessionId":"30edb2134b9b1631fdf0b53e4b3a3130","userId":"1157789261639196804"},"udp":true,"connectionData":{"ssrc":22190}}
to {"code":6,"ws":false,"udp":false}
d.js docs
d.js docs4mo ago
:guide: Getting Started: Introduction - Debugging Dependencies read more
Tommy
TommyOP4mo ago
No description
Tommy
TommyOP4mo ago
in the main folder of my project there is a folder named music with the file inside. I've tride to use absolute path now, but nothing changed, no audio. here the actual code
if (message.content === '!play') {
if (!message.member.voice?.channel) return message.channel.send('You need to be in a voice channel to execute this command');

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guildId,
adapterCreator: message.guild.voiceAdapterCreator,
debug: true
});

const player = createAudioPlayer({
debug: true
});

const resource = createAudioResource("C:\\Users\\Administrator\\Desktop\\!Assistenza Italian Paradise\\music\\song.mp3");


console.log(generateDependencyReport());

connection.subscribe(player);
player.play(resource);
}
if (message.content === '!play') {
if (!message.member.voice?.channel) return message.channel.send('You need to be in a voice channel to execute this command');

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guildId,
adapterCreator: message.guild.voiceAdapterCreator,
debug: true
});

const player = createAudioPlayer({
debug: true
});

const resource = createAudioResource("C:\\Users\\Administrator\\Desktop\\!Assistenza Italian Paradise\\music\\song.mp3");


console.log(generateDependencyReport());

connection.subscribe(player);
player.play(resource);
}
no changes with this path
const resource = createAudioResource("file:///C:/Users/Administrator/Desktop/!Assistenza%20Italian%20Paradise/music/song.mp3");
const resource = createAudioResource("file:///C:/Users/Administrator/Desktop/!Assistenza%20Italian%20Paradise/music/song.mp3");
also with this path, no audio
const resource = createAudioResource("file:///C:/Users/Administrator/Desktop/song.mp3");
const resource = createAudioResource("file:///C:/Users/Administrator/Desktop/song.mp3");
i've installed ffmpeg a few months ago and i don't remember how. i've also installed ffmpeg-static via npm recently. what's the correct method to install it?
d.js docs
d.js docs4mo ago
- npm: npm install ffmpeg-static - Install: Download | chocolatey | homebrew | your distributions package manager - Tutorial: YouTube - ffmpeg-binaries is deprecated, uninstall it with npm rm ffmpeg-binaries
Tommy
TommyOP4mo ago
so what should I do?
duck
duck4mo ago
your player seems to autopause and never resume this just means that your player doesn't think your connection is ready which is most commonly caused by missing the GuildVoiceStates intent, but the subsequent logs would indicate otherwise without any further information, I'd guess it's a network issue, but I do also see tweetnacl seems to be a little out of date as well (latest being 1.0.3) couldn't hurt to update (or even switch encryption libs), even if likely unrelated
Tommy
TommyOP4mo ago
updated, but no changes, no audio from the bot.. sorry, any solution for our problem? yo?
dzlandis
dzlandis4mo ago
Are you supposed to have three slashes after file:? Maybe try doing file://C: etc 🤷‍♂️
Tommy
TommyOP4mo ago
tried but no results Solutions???
◎-naomiluxxe
◎-naomiluxxe4mo ago
I seem to have the same issue - except the voice activity goes green from the bot, but no audio (voice activity also stops once the mp3 is finished "playing", and the debug output shows the connection going from playing to idle). My guess is that either the resource isn't getting setup properly (although it seems odd that the player would just stream silence instead of failing more loudly); or I have a configuration issue with discord. Computer audio is fine since I hear the joined earcon when the bot joins the channel . . . omg so dumb. Evidently, alerts go to system sound while Discord app has different settings for voice I/O. Changed it to the correct output and it works! fwiw, I followed the example here: https://github.com/discordjs/voice-examples/blob/main/basic/src/main.ts
Want results from more Discord servers?
Add your server