Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 959
Swoods23 Avatar asked Jun 06 '18 22:06

Swoods23


People also ask

How do you check if a user has permissions discord JS?

Checking member permissions To know if one of a member's roles has a permission enabled, you can use the .has() method on GuildMember#permissions open in new window and provide a permission flag, array, or number to check for.

How do I manage permissions in discord bot?

You can adjust permissions of specific channels, both text and voice, through the channel settings menu by hovering over a channel and clicking on the cog icon. Select the Permissions tab on the left-hand side. By default @everyone has access to all features of a channel.

What are bot permissions?

Permission HierarchyA bot can grant roles to other users that are of a lower position than its own highest role. A bot can edit roles of a lower position than its highest role, but it can only grant permissions it has to those roles. A bot can only sort roles lower than its highest role.


2 Answers

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.

like image 33
M98 Avatar answered Sep 28 '22 08:09

M98


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.

like image 149
newbie Avatar answered Sep 28 '22 07:09

newbie