Shadow Nova
Shadow Nova

Reputation: 5

Command permissions

I am looking to develop a personal network bot, I am in need of a simple "mod", "admin", and other moderation commands. I have the commands complete, I just need to figure out how to send an error & have the command not execute when the member does not have the "admin", "mod", or other moderation roles. Here is what I have so far:

if (!message.member.roles.some(r=>[Tester].includes(r.name)) ) 
return message.channel.send("error_here").catch(console.error);

I would like the code to include an error message:

message.channel.send(message.author + " you do not have permission to use this command!")

I would also like the command to not execute when the member does not have the "admin", "mod", or other moderation roles.

Upvotes: 0

Views: 104

Answers (1)

T. Dirks
T. Dirks

Reputation: 3676

I think you're on the right track, just add a little code for extra validation. This code checks if the user has any moderation roles, and if so, the command gets executed.

// Just some test role names
let modRoles = ['admin', 'moderator', 'helper'];

if (command === '<Some mod/admin command here>') {
  if (!message.member.roles.some(r=>modRoles.includes(r.name))) {
    // User does not have any moderation roles. User is not allowed to execute command
    return message.channel.send(message.author + ' you do not have permission to execute this command!');
      .catch(console.error);
  }

  // User does have a moderation role. User can execute command
  // Write code here for the command
}

Upvotes: 1

Related Questions