离开语音频道

时间:2019-04-05 18:38:40

标签: javascript node.js discord discord.js

我正在开发一个播放音乐的Discord机器人。我设法让漫游器离开了频道,但是服务器中的任何人都可以断开该频道。

我试图添加 if 语句,该语句要求命令作者的voiceChannel连接等于该行会中机器人的voiceChannel连接。

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

这将返回:

Property "voiceChannel" cannot be read of undefined.

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

1 个答案:

答案 0 :(得分:0)

要找到您的机器人在哪个频道上,请使用message.guild.me.voiceChannel。它返回机器人的当前voiceChannel。否则,client.voiceConnections.find(val => val.channel.guild.id === message.guild.id);也应该起作用。

相关问题