微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Discord JS Bot - 如何让我的机器人扫描传入消息中的关键字,然后断开用户与语音通道的连接

如何解决Discord JS Bot - 如何让我的机器人扫描传入消息中的关键字,然后断开用户与语音通道的连接

为了好玩,我刚刚开始使用 JavaScript 编写我的第一个 discord 机器人。而且我一直做得很好,直到我想让我的机器人扫描聊天中传入的消息以查找特定关键字,然后在找到该关键字后将消息作者从语音通道中踢出(如果他们已连接)。

到目前为止,我的代码如下所示:

//Checks if message content includes keyword. 
  if (msg.content.includes('what')) {

//Sets the variable "member" to be the message sender.
  const member = msg.author;

//Checks if member is in a voice channel. If not prints reply
  if (!member.voiceChannel) return msg.reply("That was a close one,I will get you next time!")

//Sets the members value to null,thus "kicking" the member out of voice channel
  member.voice.setChannel(null);
}

我收到的错误消息是:

TypeError: Cannot read property 'setChannel' of undefined

我尝试了多种变体,但没有。请帮忙!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。