【问题标题】:Make a discord.js command only available to owner使 discord.js 命令仅对所有者可用
【发布时间】:2021-06-09 00:21:16
【问题描述】:

我目前在我的 discord 机器人上使用 say 命令,但想让它只对我可用。正常命令运行良好,但一旦我插入“if (message.author.id !== '411308845714112513') return;”然后它不起作用。这是下面的原始代码供参考,我从这里的另一篇文章中得到它,我已经对其进行了测试,它工作正常:

const Discord = require("discord.js");

module.exports = {
  name: "say",
  description: "Send a message via the bot",
 async execute(message, args){

    const sayMessage = args.join(" ");
    message.delete().catch(O_o => {});
    message.channel.send(`${sayMessage}`);
  }
}

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    当我这样做时,我通常使用 if else。例如:

    if (message.author.id === 'your id here') {
    //only executes if the author is you
    } else {
    //only executes if the author is not you
    }
    

    【讨论】:

      【解决方案2】:

      你所做的完全正确。包含 if(message.author.id!=='yourid') return; 应该管用。确保您输入了正确的 ID。还要确保这个条件在命令处理程序本身之前。

      【讨论】:

      • 只是为了确保我做对了,它看起来像这样吗? const Discord = require("discord.js"); module.exports = { name: "say", description: "Send a message via the bot", async execute(message, args){ if (message.author.id !== '411308845714112513') return; const sayMessage = args.join(" "); message.delete().catch(O_o => {}); message.channel.send(${sayMessage}); } }
      【解决方案3】:

      这就是我为我的机器人做的方式。第一种方式使用权限,第二种方式使用角色。

      权限:

       if(!message.member.hasPermission("BAN_MEMBERS")) return message.reply("I cannot let you do that");
      

      角色:

              if(message.member.roles.cache.has('758292763946123295')){
       
              }
      

      【讨论】:

        猜你喜欢
        • 2021-08-05
        • 2022-07-10
        • 2019-03-05
        • 2021-01-13
        • 2021-08-09
        • 2021-02-14
        • 1970-01-01
        • 2021-08-26
        • 2021-10-11
        相关资源
        最近更新 更多