2

I don't know how to make the user leave the voice channel.

I'm trying to make a verify thing, I have it all setup except for the leave voice channel part.

bot.on('voiceStateUpdate', (oldMember, newMember) => {
  let newUserChannel = newMember.voiceChannel
  let oldUserChannel = oldMember.voiceChannel
  var channel = bot.channels.get('614299678300831744');


  if(oldUserChannel === undefined && newUserChannel !== 615306755420717143) {
    channel.send(newMember + ' has been verified.');
    let role = newMember.guild.roles.find(role => role.name === "Verified");
    newMember.addRole(role);
    let verifyEmbed = new Discord.RichEmbed()
    .setAuthor("Verificaiton")
    .setDescription("You have been verified")
    .setFooter(newMember.guild.name)
    .setColor("#98AFC7")
    newMember.sendMessage(verifyEmbed);
    newMember.disconnect();
  }
});

I don't get any error, but it should disconnect me from the voice channel but can't?

asciidude
  • 272
  • 1
  • 3
  • 19

5 Answers5

9

Instead of newMember.disconnect(); use newMember.setVoiceChannel(null);

Here is the related documentation

I use this on my bot and it works fine.

BadSpencer
  • 106
  • 2
  • 6
6

Not sure if this is still relevant but since the update you can now do the following.

newMember.member.voice.disconnect();

Refer to the VoiceState class method disconnect.

Intel
  • 173
  • 1
  • 7
4

The problem is that .disconnect() is not a method of the GuildMember class. All of the methods that can be used on a GuildMember can be found here.

.disconnect() is only a method that exists on a voiceChannel, and is used to "Disconnect the voice connection, causing a disconnect and closing event to be emitted." 1

From what i can tell, there is no possible way to forcibly remove a user from a voice channel.

Snel23
  • 1,381
  • 1
  • 9
  • 19
  • Is there any way I can make a voice channel named the user's id, connect them to that channel, then delete it? – asciidude Aug 26 '19 at 08:34
  • 3
    There is no way to forcibly connect someone to a voice channel either, they will have to do it themselves. – Snel23 Aug 26 '19 at 23:29
2

You can make the bot create a new voice channel, move the user to the newly created voice channel, delete that channel and thus the user being disconnected

let randomnumber = Math.floor(Math.random() * 9000 + 1000)

await receivedMessage.guild.createChannel(`voice-kick-${randomnumber}`, "voice")
await vcUser.setVoiceChannel(receivedMessage.guild.channels.find(r => r.name === `voice-kick-${randomnumber}`))
receivedMessage.guild.channels.find(r => r.name === `voice-${randomnumber}`).delete()

Were adding the randomnumber command to make a random number in the VC so that there aren't any VC's that have the same name!

antonivan
  • 68
  • 1
  • 1
  • 5
1

In order to disconnect a user from a voice channel, you can use this way

newMember.voice.disconnect();

I use this for my bot so it works

Sipron
  • 11
  • 1