I can't figure out why my bot is not playing music. This is my code.
if (command === 'song') {
const player = createAudioPlayer();
joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
}).subscribe(player);
message.guild.me.voice.setRequestToSpeak(true);
const resource = createAudioResource('music/song.mp3');
player.play(resource);
}
I'm using Discordjs 13, installed all the required modules... the bot joins the voice channel but it doesn't play the song in my local folder. Edit: The console does not return errors, the bot has administrator permissions and it is not muted or deafened.
Edit 2:
This is the report I got from the console when I use generateDependenciesReport()
--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.7.4
- prism-media: 1.3.2
Opus Libraries
- @discordjs/opus: 0.5.3
- opusscript: not found
Encryption Libraries
- sodium: not found
- libsodium-wrappers: 0.7.9
- tweetnacl: not found
FFmpeg
- version: 4.4.1-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
And I think that everything's okay but the bot is still not playing music
Edit 3:
I edited my code to this
if (!message.member.voice.channel) {
return
} else if (message.member.voice.channel) {
const connection = joinVoiceChannel({
channelId: message.member.voice.channel.id,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator
});
const player = createAudioPlayer();
const resource = createAudioResource('./music/song.mp3');
//play the song resource
player.play(resource);
connection.subscribe(player);
}
Still no console errors, the bot joins the voice channel but it doesn't play the .mp3 file. Any ideas ?
I finally solved my problem.
The thing I was missing was an intent of the client. It was GUILD_VOICE_STATES.