简体   繁体   中英

How to get role permissions ? Discord.js

I'm trying to make a bot that analyzes the server to find a flaw but I can't find how to know a precise authorization for a role? I have already tested this:

var role = message.mentions.roles.first()

if(role.permissions.has(Discord.Permissions.FLAGS.KICK_MEMBERS)){
     message.reply("YES") 
}
else message.reply("NO")

I always receive Yes as a message

You are doing the if/else wrong, instead do it like this:

var role = message.mentions.roles.first()

if (role.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
    message.reply({ content: "YES" })
} else {
    message.reply({ content: "NO" })
}

You don't need to put Discord infront of Permissions, and message.reply('') is deprecated, instead use message.reply({ content: '' })

 Old: channel.send(embed);
 New: channel.send({ embeds: [embed, embed2] });

 Old: channel.send('Hello!', { embed });
 New: channel.send({ content: 'Hello!', embeds: [embed, embed2] });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM