EduCheck
EduCheck

Reputation: 11

discord.js bot won't leave voice channel


I tried almost everything to make my bot leave from the voice channel, but the bot won't leave it. Source code:

Discord.VoiceConnection.disconnect();

This is the current code, but I have used

message.member.voice.channel.disconnect()
message.member.voice.channel.leave()
message.member.voiceChannel.disconnect()
message.member.voiceConnection.leave()
message.member.voiceChannel.leave()
...etc.

The reason I use VoiceConnection.disconnect() is my older function connection.disconnect(); works and the bot leaves.
I tracked where connection came from and the result was from VoiceConnection and from there
I tried using Discord.VoiceConnection. But still the bot doesn't wan't do leave. I am currently using v12. Can anybody help?

Upvotes: 1

Views: 8995

Answers (2)

Luuk
Luuk

Reputation: 711

If you are using the normal discord.js package for voice

message.guild.me.voice.channel.leave()

should work. Here are you looking for the voice channel where the bot is currently in and you leave it.

If you are using the @discordjs/voice package for voice you should use

const voice = require('@discordjs/voice');
voice.getVoiceConnection(`guild_id`).disconnect();

Upvotes: 2

PLASMA chicken
PLASMA chicken

Reputation: 2785

Try using

message.guild.me.voice.channel.leave();

message.guild.me is the Bot's Member Object in this guild, and so you get the channel and can leave it.

Upvotes: 0

Related Questions