#How Can I make the bot leave a channel without having the connection that was created on his join ?

19 messages · Page 1 of 1 (latest)

weak roost
#

When the bot joins a channel it creates a connection with the joinVoiceChannel() function but when we reset the bot the voiceConnection is not kept so my question is how can I get the connection of the bot in a channel without having the first connection object ? My goal is to make him leave the channel.

runic hedgeBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
weak roost
#
client.on('voiceStateUpdate', async (oldState, newState) => {

    let member = newState.member
    if (!member.user || (member.user.bot && member.user.id != client.user.id)) return

    let queue = client.queue.get(newState.guild?.id)
    if (queue && queue != null && queue != undefined) {

    }
    else {
        if (oldState.channel.members.has(client.user.id)) {
            //Here I want to kick the bot from the vocal
        }
    ```
#

I know that the code is not really good for now, I m working on it, I just want to know how to kick himfrom the channel

alpine vergeBOT
weak roost
#

Wait, the bot need to have the permission to kick members from the voice channel to disconnect himself ?

#

I mean the "Move Members" permission

lost citrus
#

It shouldn’t, no

weak roost
#
if (channel?.guild?.members?.me?.voice && checkIfBotIsInVocal(channel)) {
        console.log("Bot leave channel")
        try {
            await channel.guild.members.me.voice.disconnect()
        } catch (e) {
            //console.error(date() + "Leave error: " + e)
        }
    }
#

Channel is a valid channel

#

and I tried for setChannel too

#

same error

#

Missing Permissions

lost citrus
#

Oh, true, that doesn’t use the correct method for the ClientUser. You‘d need to joinVoiceChannel(…) with channelId:null instead