简体   繁体   English

离开语音频道

[英]Leave voice channel

I'm working on a discord bot that plays music. 我正在研究一种播放音乐的不和谐机器人。 I have managed to get the bot to leave the channel, but anyone in the server can disconnect it. 我设法让机器人离开频道,但服务器中的任何人都可以断开它。

I have tried to add an if statement that requires the command author's voiceChannel connection to be equal to the bot's voiceChannel connection in that guild. 我试图添加一个if语句,要求命令作者的voiceChannel连接等于该公会中bot的voiceChannel连接。

if(client.guildChannel.voiceChannel == message.author.voiceChannel)
        {
            message.guild.voiceConnection.disconnect(); 
        }

this returns: 这会返回:

Property "voiceChannel" cannot be read of undefined.

I can't find anything on the documentation that defines which voice channel the bot is connected to in which guild. 我在文档中找不到任何定义机器人连接到哪个语音通道的文档。

To find on which channel your bot is, use message.guild.me.voiceChannel . 要查找机器人所在的渠道,请使用message.guild.me.voiceChannel It return the current voiceChannel of the bot. 它返回bot的当前voiceChannel。 Otherwise, client.voiceConnections.find(val => val.channel.guild.id === message.guild.id); 否则, client.voiceConnections.find(val => val.channel.guild.id === message.guild.id); should also work. 也应该工作。

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

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