【问题标题】:How do i make my command return if a bot is mentioned?如果提到机器人,我如何让我的命令返回?
【发布时间】:2020-11-04 00:53:40
【问题描述】:

这是我的命令的开始。我试过if(member === bot) return message.channel.send("You can't rob bots") 但它没有用,任何帮助将不胜感激

client.on('message', async message => {
  if(message.content.startsWith("$$rob")) {
const member = message.mentions.members.first()
if(!member) return message.channel.send("You need to mention a user to rob them")

【问题讨论】:

  • member.id === bot.id 可能会更好,因为可能有两个不同的对象实例引用同一个成员。

标签: javascript node.js discord.js quick.db


【解决方案1】:

试试这个:

if(member.user.bot) {
    return message.channel.send("You can't rob bots")
}

【讨论】:

    【解决方案2】:

    member === bot 不是检查成员是否是机器人的正确方法。请记住,=== 符号检查它两侧的变量是否相等(在三等号的情况下,还检查它们是否属于同一类型)。 bot 不是你声明的变量,所以这不是你的做法。

    相反,检查成员的user 属性,即成员对象背后的用户。检查documentation,您会发现用户有一个名为bot 的布尔属性,它告诉您它是否是机器人。因此,检查成员是否为机器人的正确方法是:

    if(member.user.bot === true) {
        //Do stuff
    }
    

    当然也可以简化:

    if(member.user.bot) {
        //Do stuff
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 2021-08-03
      • 2020-08-14
      • 2021-01-27
      相关资源
      最近更新 更多