Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Join an specific voice channel when the bot is ready in discord.js v13

I found some articles about this question. like this.

But it was in discord v12. I want discord.js v13

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

client.on("ready", async() => {
const { joinVoiceChannel } = require('@discordjs/voice');
joinVoiceChannel({
            channelId: "863783336860975114",
            guildId: "847071265100791849",
            adapterCreator: channelId.guild.voiceAdapterCreator
        })

// It does not work
}

How can I make my bot that it joins a specific channel when it’s ready?

I am using discord.js v13 and node.js v16.15

>Solution :

In the documentation for @discordjs/voice an in the discord.js guide we see:

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

const connection = joinVoiceChannel({
    channelId: channel.id,
    guildId: channel.guild.id,
    adapterCreator: channel.guild.voiceAdapterCreator,
});

You need to fetch the guild or channel first since you need to use a voiceAdapterCreator.

You can use something like client.channels.fetch to get the channel object.

Example code to put inside ready event:

client.channels.fetch(id) // voice channel's id
    .then((channel) => { // channel object

        const VoiceConnection = joinVoiceChannel({
            channelId: channel.id, // the voice channel's id
            guildId: channel.guild.id, // the guild that the channel is in
            adapterCreator: channel.guild.voiceAdapterCreator // and setting the voice adapter creator
        });
    });

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading