user14897096
user14897096

Reputation:

Say what permissions a user has discord.js

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

Answers (2)

Androz2091
Androz2091

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

Liam
Liam

Reputation: 957

You can do this with GuildMembers#permissions.

"The overall set of permissions for this member, taking only roles into account"

Upvotes: -1

Related Questions