查看命令是否执行

Check if command is executed

我的命令限制系统有问题。
消息“您没有权限”只会 运行 一次(当您没有该角色时)。我知道如果您不设置 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) 将以 prefix + command 开头。所以你可以这样写:

// Assuming that:
// var prefix = '-'; for example
if (message.content.startsWith(prefix + "mycommand")) {
  checkrole = false;
}

尽管这行得通,但还有更有效的方法来使用命令,尤其是当您需要使用参数等时...
阅读 this guide 可能会对您有所帮助:它涵盖了基础知识,但也涵盖了更高级的内容 ;)