命令权限

时间:2019-01-25 05:59:12

标签: discord.js

我正在寻找一个个人网络机器人,我需要一个简单的“ mod”,“ admin”和其他审核命令。我已经完成了命令,只需要弄清楚如何发送错误并在成员没有“ admin”,“ mod”或其他审核角色时使命令不执行。这是我到目前为止的内容:

if (!message.member.roles.some(r=>[Tester].includes(r.name)) ) 
return message.channel.send("error_here").catch(console.error);

我希望代码包含错误消息:

message.channel.send(message.author + " you do not have permission to use this command!")

我还希望成员没有“ admin”,“ mod”或其他审核角色时执行命令。

1 个答案:

答案 0 :(得分:1)

我认为您的方向正确,只需添加一些代码即可进行额外的验证。该代码检查用户是否具有任何主持角色,如果有,则命令将被执行。

// Just some test role names
let modRoles = ['admin', 'moderator', 'helper'];

if (command === '<Some mod/admin command here>') {
  if (!message.member.roles.some(r=>modRoles.includes(r.name))) {
    // User does not have any moderation roles. User is not allowed to execute command
    return message.channel.send(message.author + ' you do not have permission to execute this command!');
      .catch(console.error);
  }

  // User does have a moderation role. User can execute command
  // Write code here for the command
}
相关问题