Discord.js如何检查命令中的提及用户是否具有角色?

时间:2020-09-09 11:07:49

标签: javascript node.js discord discord.js

我想创建一个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.*'
 );
}

1 个答案:

答案 0 :(得分:0)

您可以使用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页面