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

javascript - Checking if the author of a message is an Administrator - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Aug 27, 2018 at 18:49 André 4,4974 gold badges32 silver badges58 bronze badges asked Aug 26, 2018 at 22:11 It's WillemIt's Willem 8163 gold badges9 silver badges15 bronze badges 2
  • Are you sure this is a Discord.JS question? DiscordJS events don't really look like that, and that tag should only be used for questions for DiscordJS – André Commented Aug 27, 2018 at 8:27
  • 1 @André OP appears to be using discord.io (this is why my discord bots event handlers look like) – Nick is tired Commented Aug 27, 2018 at 15:41
Add a comment  | 

2 Answers 2

Reset to default 12

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!')
  });

More up to date answer:

function isAdmin(msg) {
  return msg.member.permissionsIn(msg.channel).has("ADMINISTRATOR")
}
发布评论

评论列表(0)

  1. 暂无评论