Reputation:
I am trying to make a command in Discord.js that reads what permissions a user has. For example, you could do
$permissions @user
and it would return with something like this:
"Users permissions in this guild are: "
etc.. I am not sure if this is even possible, though if it is, some guidance on where i could start would be greatly appreciated!
Upvotes: 0
Views: 508
Reputation: 3005
This is possible because discord.js has a list of all the available permissions, so you loop on them and check if the user has the permission or if they don't have it.
const Discord = require('discors.js');
const client = new Discord.Client();
client.login('token');
client.on('message', (message) => {
if (message.content === 'list-permissions') {
// get the list of permissions
const permissions = Object.keys(Discord.Permissions.FLAGS);
message.channel.send(
'Permissions of ' + message.author.username + '\n\n' +
permissions.map((perm) => {
return message.member.hasPermission(perm) ? `${perm}: YES` : `${perm}: NO`
}).join('\n');
);
}
});
This will return something like:
Permissions of Androz2091
MANAGE_MESSAGES: YES
BAN_MEMBERS: NO
KICK_MEMBERS: YES
etc...
Upvotes: 1
Reputation: 957
You can do this with GuildMembers#permissions.
"The overall set of permissions for this member, taking only roles into account"
Upvotes: -1