简体   繁体   中英

how do I make only certain roles use this command?

how do I make only certain roles use this command?

  if (!message.member.hasPermission()) return;
  if (mention == null) return;
  if (message.guild.member(mention).hasPermission()) return;
  let reason = message.content.slice (prefix.lenght + mention.toString().lenght + 5);
  message.cannel.send (mention.username + );
  mention.sendMessage ().then (d_msg => {
    messge.guild.member(mention).ban(reason);
  })
}```

You can use the GuildMember 's roles to check if they have the role

Using the role's name

if (!message.member.roles.some(role => role.name === 'Role Name')) return

Or using the role's ID

if (!message.member.roles.some(role => role.id === 'Role_ID')) return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM