离开语音频道

Leave voice channel

我正在开发一个播放音乐的 discord 机器人。我已经设法让机器人离开频道,但服务器中的任何人都可以断开它。

我尝试添加一个 if 语句,要求命令作者的语音通道连接等于该公会中机器人的语音通道连接。

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

这个returns:

Property "voiceChannel" cannot be read of undefined.

我在文档中找不到任何定义机器人连接到哪个公会的语音通道的内容。

要查找您的机器人所在的频道,请使用 message.guild.me.voiceChannel。它 return 机器人的当前 voiceChannel。否则,client.voiceConnections.find(val => val.channel.guild.id === message.guild.id); 也应该有效。