【问题标题】:Command permissions命令权限
【发布时间】:2019-06-18 23:02:55
【问题描述】:

我正在寻找开发个人网络机器人,我需要一个简单的“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”或其他审核角色时执行命令。

【问题讨论】:

    标签: discord.js


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      相关资源
      最近更新 更多