Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if the author of a message is an Administrator

I'm writing a Discord bot that uses the following code to detect and process user messages:

bot.on('message', function (user, userID, channelID, message, evt) {
  //Message handling and response code goes here
});

I want to add a command that only works if the user who sent it has the Administrator permission. Is there a way I could do this?

like image 751
It's Willem Avatar asked Dec 24 '22 04:12

It's Willem


2 Answers

Here is an example how you could do this:

bot.on('message', function (user, userID, channelID, message, evt) {
    if (message.member.hasPermission("ADMINISTRATOR")) return console.log('THIS USER HAS ADMINISTRATOR PERMISSIONS!')
  });
like image 164
Gilles Heinesch Avatar answered Dec 25 '22 23:12

Gilles Heinesch


More up to date answer:

function isAdmin(msg) {
  return msg.member.permissionsIn(msg.channel).has("ADMINISTRATOR")
}
like image 33
loloToster Avatar answered Dec 25 '22 23:12

loloToster