代码之家  ›  专栏  ›  技术社区  ›  qtt qtt

角色独占命令不工作//不一致。js公司

  •  1
  • qtt qtt  · 技术社区  · 7 年前

    我的代码当前为:

    if (message.content == ",test") {
        if (message.member.roles.find("name", "images")) {        
            message.channel.send( {
                file: "http://www.drodd.com/images14/black11.jpg" // Or replace with FileOptions object
            });
        }
        if (!message.member.roles.find("name", "images")) { // This checks to see if they DONT have it, the "!" inverts the true/false
        message.reply('You need the \`images\` role to use this command.')
        .then(msg => {
          msg.delete(5000)
        })
        }
        message.delete(100); //Supposed to delete message
        return; // this returns the code, so the rest doesn't run. 
    }
    

    如果用户具有“images”角色,我希望bot在他们说“test”时发送图像,并且我希望用户的“test”消息在几秒钟后被删除。然而,这似乎不起作用。

    我尝试在不进行角色检查的情况下发送图像,效果很好。

    我怎样才能解决这个问题?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Axiumin_    7 年前

    这是因为 message.member.roles.find("name", "images") 检查角色 存在 在公会中。为了确定某人是否有角色,您可以使用 message.member.roles.has(myRole) . 要动态查找角色的ID,可以使用以下方法: let myRole = message.guild.roles.find("name", "Moderators").id; .