Imaginebeingme
Imaginebeingme

Reputation: 175

How do I have bot ignore certain role(s) // Discord.js

I made a simple auto-ban command with the following $kek command. Currently, anybody at any role can use this. I want it to ignore (a) certain role(s). For example, anybody with admin permissions could use it without being banned. How would I input that for the bot to ignore?

Code as follow

   exports.exec = (Cuckbot, message) => {
 // Won't catch log errors because I can't be fucked, you can tell if it ran correctly or not. 
 // Bans users if they use $kek command.
 // Bot will notify afterwards that he was banned.

 if(message.content.startsWith("$kek")) { 
 message.member.ban("Dumbass used $kek") } // Audit log message

 message.channel.send({
    embed: {
      color: 0,
      description: `${message.author} just banned himself. 👮`
    }
  }).catch(e => {
    Cuckbot.log.error(e);
  });
};

Upvotes: 0

Views: 2777

Answers (1)

Gilles Heinesch
Gilles Heinesch

Reputation: 2980

You can check if the member has a specific permissions using the following code:

if (message.member.hasPermission("SEND_MESSAGES")) return message.reply('You are not allowed to use this commmand')

or to check more than one permission:

if (message.member.hasPermissions(["SEND_MESSAGES", "MANAGE_SERVER"])) return message.reply('You are not allowed to use this commmand')

All permission flags can be found here: https://discord.js.org/#/docs/main/stable/class/Permissions?scrollTo=s-FLAGS

To ignore certain roles, you can use the following:

if (message.member.roles.has("ROLE ID")) return message.reply('You are not allowed to use this commmand')

Upvotes: 1

Related Questions