Discord. Js: Checking Bot Permissions

This is probably a nub question, but I can't seem to figure it out. I'm trying to make my bot check if it has a permission, and send a message if does not. I'm guessing it like this code to check it a member has a permission:

message.member.hasPermission("MUTE_MEMBERS")

Is it like that to get a bots permissions? Any help would be appreciated!

5 Answers

message.member gets the GuildMember object of the author who sent the message. Looks like you actually want to get the GuildMember object of the client instead. You can do this by doing <Client>.guild.me and then call .hasPermission(...) on this.

If you want to check if the bot has a permission you can do something like:

if(message.guild.me.hasPermission("MUTE_MEMBERS"))
    console.log("I can mute members!!")
else
    console.log("I CAN'T mute members!")

F.M.

message.guild.me.hasPermission("MUTE_MEMBERS")
3

In discord.js V13 you can check for permissions this way:

 if (message.member.permissions.has("MUTE_MEMBERS")){
    // ....
 } else { 
    //....
 }
if(!message.member.hasPermission("PERMISSION") return message.channel.send("You don't have permission to use this command")

Embeds:

const embed = new MessageEmbed()
.setTitle("No Permission")
.setDescription("You don't have permission to use this command")

if(!message.member.hasPermission("PERMISSION") return message.channel.send(embed)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest