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

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.
4 Replies
d.js toolkit
d.js toolkit7mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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
}

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
d.js docs
d.js docs7mo ago
:method: 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 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)
}
}
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 Ohh interesting, I'll try that, thanks again
Want results from more Discord servers?
Add your server