How to make the bot leave a voice chat?

I have tried several options:
let connection = getVoiceConnection(interaction.guild.id);
if (connection === undefined) {
await interaction.reply("I am not in a vc!");
return;
};
connection.destroy();
let connection = getVoiceConnection(interaction.guild.id);
if (connection === undefined) {
await interaction.reply("I am not in a vc!");
return;
};
connection.destroy();
interaction.guild.members.me.voice.channel.leave()
interaction.guild.members.me.voice.channel.leave()
interaction.guild.member.voice.channel.leave()
interaction.guild.member.voice.channel.leave()
none working.
8 Replies
d.js toolkit
d.js toolkit2y 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
vlady.dev
vlady.devOP2y ago
No description
dzlandis
dzlandis2y ago
connection.destroy() should make the bot leave the voice channel If it's not working, there is something else wrong with your code.
vlady.dev
vlady.devOP2y ago
connection is undefined The bot is in the vc tho
dzlandis
dzlandis2y ago
Are you using the correct guildId when running getVoiceConnection()? Like are you running that command in the same guild as where the bot is connected to the voice channel?
vlady.dev
vlady.devOP2y ago
Yeah ofc I'm not that dumb to run it elsewhere
Aman
Aman2y ago
it's me.voice.disconnect() That happens when there's a network interruption of any kind (e.g. restarting your bot without leaving the voice channel first, etc)
vlady.dev
vlady.devOP2y ago
Thanks a lot Aman. I thought it's voice.channel.disconnect

Did you find this page helpful?