IHZAQ
IHZAQ

Reputation: 102

Discord Command Permissions

I was creating a admins commands for my discord bot. I know how to know code bans command thing. but I want to make sure that this command only admins permission can use it.Can someone show me how to do it? thanks. Here my codes

client.on('message', async message =>{
  if(message.author.bot) return;
  if(message.content === "ban"){
    message.channel.send("Users Have been banned, lol")
  }
})

Upvotes: 0

Views: 142

Answers (1)

MrMythical
MrMythical

Reputation: 9041

Use GuildMember.permissions

client.on('message', async message => {
  if (message.author.bot) return;
  if (!message.member.permissions.has(Discord.Permissions.FLAGS.BAN_MEMBERS)) return;
  if (message.content === "ban") {
    message.channel.send("Users Have been banned, lol")
  }
})

You can send an information message in the return statement:

if (!message.member.permissions.has(Discord.Permissions.FLAGS.BAN_MEMBERS)) return message.channel.send("You need permissions!");

You can choose any permission with Permissions.FLAGS

Upvotes: 2

Related Questions