我的命令限制系统有问题。
“您没有权限”消息只会运行一次(当您没有该 Angular 色时)。我知道,如果您不设置 var(在本例中为 checkrole
),代码将执行一次,但是,我不知道如何检查命令何时执行。
所以我可以做这样的事情:
if (command === ' ') {
checkrole = false
}
感兴趣的代码:
if (!message.member.roles.some(r => ["someone"].includes(r.name.toLowerCase())) && checkrole === false) {
checkrole = true;
return message.channel.send('Sorry, but you do not have the **permissions** to do that.');
}
(var checkrole 已定义 - 它以 false 开头 (var checkrole = false;
))
亲切的问候, 鲁本
最佳答案
通常,如果您想使用命令,则需要前缀。一旦您选择了该选项,您就知道消息的内容 ( Message.content
) 将以 前缀 + 命令
开头。所以你可以这样写:
// Assuming that:
// var prefix = '-'; for example
if (message.content.startsWith(prefix + "mycommand")) {
checkrole = false;
}
虽然这可行,但还有更有效的方法来使用命令,特别是当您需要使用参数等时......
正在阅读this guide可能对您有帮助:它涵盖了基础知识,但也涵盖了更高级的内容;)
关于javascript - 检查命令是否执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52677598/