简体   繁体   English

discord.js bot 不会离开语音通道

[英]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();我使用 VoiceConnection.disconnect() 的原因是我的旧 function connection.disconnect(); works and the bot leaves.工作,机器人离开。
I tracked where connection came from and the result was from VoiceConnection and from there我跟踪了connection的来源,结果来自VoiceConnection和那里
I tried using Discord.VoiceConnection .我尝试使用Discord.VoiceConnection But still the bot doesn't wan't do leave.但是机器人仍然不想离开。 I am currently using v12.我目前正在使用 v12。 Can anybody help?有人可以帮忙吗?

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. message.guild.me 是这个公会的 Bot 成员 Object,所以你得到了频道就可以离开了。

If you are using the normal discord.js package for voice如果您使用普通 discord.js package 进行语音

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如果您使用 @discordjs/voice package 进行语音,您应该使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM