最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.js: Checking Bot Permissions - Stack Overflow

programmeradmin2浏览0评论

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!

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!

Share Improve this question asked Jun 6, 2018 at 22:57 swoodsswoods 3732 gold badges5 silver badges12 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 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.

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")

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)
发布评论

评论列表(0)

  1. 暂无评论