4

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 5

9

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

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

3 Comments

Please add more details to the solution. Also, please follow StackOverflow guidelines - stackoverflow.com/help/how-to-ask
put some more explanations
@Harshit stackoverflow.com/help/how-to-answer would be for answers. The link you posted would apply to questions. Another good tip would be to always read a page before you link it.
1

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

 if (message.member.permissions.has("MUTE_MEMBERS")){ // .... } else { //.... } 

Comments

-1
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 Comment

For checking bot permission same thing with another variable

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.