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 |2 Answers
Reset to default 12Here 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")
}
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:27discord.io
(this is why my discord bots event handlers look like) – Nick is tired Commented Aug 27, 2018 at 15:41