Justin
Justin

Reputation: 33

Discord.js setVoiceChannel

I can't for the life of me figure out what I am doing wrong, I'm trying to disconnect a specific user when using this. Here's what I wrote

bot.on('message', message => {
    if (message.content.startsWith("test")) {
        bot.fetchUser('(my userid here)').then((user) => {
            user.setVoiceChannel(null);
        });
    }
})

Upvotes: 0

Views: 1203

Answers (1)

Cipher
Cipher

Reputation: 2722

Use guild.member.get for find user.

bot.on('message', message => {
    if (message.content.startsWith("test")) {
        let targetUser = message.guild.members.get('ID')
        if(targetUser) {
            targetUser.setVoiceChannel(null)
                .then(() => console.log(`Disconnect ${targetUser.displayName} from voiceChannel`))
                .catch(console.error);
        }
    }
})

Upvotes: 1

Related Questions