#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)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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
[email protected]
node version v20.12.0
@discordjs/[email protected]
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
VoiceState#setChannel()
Moves the member to a different channel, or disconnects them from the one they're in.
Thanks !
I ll try this
Wait, the bot need to have the permission to kick members from the voice channel to disconnect himself ?
I mean the "Move Members" permission
It shouldn’t, no
Well maybe I m doing something wrong
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
Oh, true, that doesn’t use the correct method for the ClientUser. You‘d need to joinVoiceChannel(…) with channelId:null instead