【问题标题】:Discord.js How can I check if a mention user in my command has a role?Discord.js 如何检查我的命令中的提及用户是否具有角色?
【发布时间】:2020-12-27 19:26:33
【问题描述】:

我想创建一个if 语句来检测消息作者是否具有名为System Control Authority - 50 的角色。如果是这样,他们就不能使用该命令。我该怎么做?

const sys10 = client.guilds.cache
 .get('745816516238245888')
 .roles.cache.find((role) => role.name === 'System Control Authority - 10');

if (cmd == 'aerial') {
 message.delete({ timeout: 10 });
 if (!sys10 && !devRole && !adminRole && !qgRole && !qgtsRole) {
  return func.Loi(
   'You cannot use this command.\nRequire role: **System Control Authority - 10**'
  );
 }
 const takelinda = message.mentions.members.first().id;
 if (takelinda == '669723732708687882') {
  return func.Loi(message, 'You cannot use this command to me =)))');
 }
 return message.channel.send(
  '*<@' +
   message.author.id +
   '>:*\nSystem Call.\nGenerate Aerial Element.\nBurst Element!\n*<@' +
   takelinda +
   '>: ahhhhh*\n*System: <@' +
   takelinda +
   '> has been defeated.*'
 );
}

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以使用Collection#some 方法。

    // get the member's roles, check if any of them pass the name test
    if (message.member.roles.cache.some(role => role.name === 'System Control Authority - 10')
      return func.Loi(message, 'You have the System Control Authority - 10 role, so you cannot use this command')
    

    欲了解更多信息,请访问官方discord.js指南中的thisthis页面?

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 2021-05-30
      • 2021-10-25
      • 1970-01-01
      • 2018-07-09
      • 2021-01-02
      • 2022-01-19
      • 2020-09-21
      • 2021-07-06
      相关资源
      最近更新 更多