简体   繁体   中英

Discord.js joining voice channel

I need my bot joins a voice channel on ready here is my code


const { joinVoiceChannel } = require('@discordjs/voice');
client.on('ready', () => {
        joinVoiceChannel({
            channelId: client.channels.cache.get('862785346767814696')
        })
})

it return with error (o is not a function)

Try this.

client.on("ready", () => {
    const channel = client.channels.cache.get("862785346767814696");
    if (!channel) return console.error("The channel does not exist!");
    channel.join().then(connection => {
        console.log("Successfully connected.");
    }).catch(e => {
        console.error(e);
    });
});

You have to specify a guild ID and voice adapter creator

joinVoiceChannel({
  channelId: "channelId",
  guildId: "guildId",
  adapterCreator: client.guilds.cache.get("guildId").voiceAdapterCreator
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM