Home > database >  How do I disconnect a user from a discord channel with discord js?
How do I disconnect a user from a discord channel with discord js?

Time:02-08

I am new to using JavaScript and Discord JS. I've been stuck on this issue for a while and have been looking around for solutions but it seems I am a little lost on this as nothing I've tried has worked.

The main issue seems to be that things are undefined. For example, a very simple version of something I have tried:

else if (message.content.startsWith("!dc")) {
    message.author.voice.setChannel(null);
}

Resulting in the terminal returning:

TypeError: Cannot read properties of undefined (reading 'setChannel')

I'm not quite sure how to "define" these as some solutions I've found online seem to do what I am trying to do in a similar way. Am I just missing something obvious?

I also have these Intents declared at the top.

const client = new Discord.Client({
intents: [
    Discord.Intents.FLAGS.GUILDS,
    Discord.Intents.FLAGS.GUILD_MESSAGES,
    Discord.Intents.FLAGS.GUILD_VOICE_STATES,
    Discord.Intents.FLAGS.GUILD_MEMBERS
]

});

Thanks for any help or advice on how to solve this issue.

CodePudding user response:

What Bee said in the comments to my post! Thanks!

CodePudding user response:

I don't think you can set disconnect yourself while you are admin. So try this

return <member>.voice.setChannel(null)
    .then(() => message.channel.send(`Done`))
    .catch((err) => message.channel.send(`\\❌ | ${err}!`));
  •  Tags:  
  • Related