【问题标题】:Role exclusive commands not working // Discord.js角色独占命令不起作用 // Discord.js
【发布时间】:2018-06-05 20:31:25
【问题描述】:

我的代码目前是:

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. 
}

如果用户具有“图像”角色,我希望机器人在他们说“,测试”时发送图像,并且我希望在几秒钟后删除用户的“,测试”消息。但是,这似乎不起作用。

我已尝试在不检查角色的情况下发送图像,并且有效。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript node.js bots discord discord.js


    【解决方案1】:

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

    【讨论】:

    • 您好,感谢您的回复。我试过了,但没有用。这是控制台错误:TypeError: message.guild.roles.find(...).id.catch is not a functionprntscr.com/hrg72k
    • 我已经删除了捕获,因为这可能会导致问题。
    猜你喜欢
    • 1970-01-01
    • 2020-10-07
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2018-07-28
    • 1970-01-01
    • 2021-05-22
    相关资源
    最近更新 更多