Discord Bot Not Playing Audio discord.js v13
Asked Answered
H

3

6

I'm trying to make a discord bot that can play mp3 files in a voice channel.. but it doesn't seem to work as intended


            connection = joinVoiceChannel({
                channelId: voice.channelId,
                guildId: interaction.guildId,
                adapterCreator: voice.channel.guild.voiceAdapterCreator,
            });
            
            
            let resource = createAudioResource(createReadStream(join(__dirname, 'resources/try.mp3')), {
                inlineVolume : true
            });

            resource.volume.setVolume(0.2);

            console.log(join(__dirname, 'resources/try.mp3'));
            
            const player = createAudioPlayer();

            connection.subscribe(player);
            player.play(resource)
            console.log("done");

            await interaction.reply('I have joined the voice channel!');

It successfully joined the voice channel, but it does not play any sound at all

The bot joined the voice channel

I have made sure that the directory name is correct by console.logging join(__dirname, 'resources/try.mp3')

I have also tried to check the required dependency for playing audios in discord.js v13

const { generateDependencyReport } = require('@discordjs/voice');

console.log(generateDependencyReport());

here's the output:

--------------------------------------------------
Core Dependencies
- @discordjs/voice: 0.6.0
- 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-essentials_build-www.gyan.dev
- libopus: yes
--------------------------------------------------

I think the discord.js v13 docs said that it only requires any one of each Core , Opus, Encryption, and FFmpeg Dependencies (Correct me if I'm wrong)

Did I miss anything?

Thank you in advance

Hepplewhite answered 25/9, 2021 at 15:36 Comment(0)
P
3

Happened the exact same to me. The problem is in the intents you set in the new Discord.js. More is in the reddit thread link.

https://www.reddit.com/r/Discordjs/comments/pprpit/voice_connection_stuck_in_the_signalling_state/

Phraseograph answered 25/9, 2021 at 22:25 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Synovitis
H
6

Thanks, It worked!

I actually didn't show this line in my question:

I changed

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

to:

const myIntents = new Intents();
myIntents.add(Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_VOICE_STATES);

const client = new Client({ intents: myIntents });

It plays sound as intended now

Bot plays sound

Hepplewhite answered 25/9, 2021 at 22:59 Comment(0)
P
3

Happened the exact same to me. The problem is in the intents you set in the new Discord.js. More is in the reddit thread link.

https://www.reddit.com/r/Discordjs/comments/pprpit/voice_connection_stuck_in_the_signalling_state/

Phraseograph answered 25/9, 2021 at 22:25 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Synovitis
L
1

Update for Discord.js version 14. After checking the version 14 documentation, I was able to get this working in version 14 with the following:

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildVoiceStates,
  ], 
});

See the Discordjs guide page on intents for reference: https://discordjs.guide/popular-topics/intents.html#privileged-intents

Landlady answered 17/4, 2023 at 0:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.