Check User Perms

Aquí tienes la documentación en inglés:


Using checkUserPerms to Verify User Permissions

  1. Importing Functions:

    const { newCommand, checkUserPerms } = require('mvk-project');

    First, we import newCommand and checkUserPerms from the mvk-project package. This will allow us to define a new command and check if a user has the necessary permissions to execute it.

  2. Defining a New Command:

    newCommand({
      name: 'test-command',
      code: async function (message) {
      }
    });

    We define a new command called test-command. This command will be executed when invoked in a message.

  3. Checking User Permissions:

    const result = await checkUserPerms({
      user: message.author.id, 
      permissions: ['ADMINISTRATOR', 'MANAGE_GUILD'], 
      guildId: message.guild.id
    });

    Inside the command's code function, we use checkUserPerms to verify if the user who sent the message has the required permissions (ADMINISTRATOR and MANAGE_GUILD) in the specific Discord server (guild).

  4. Handling Permission Results:

    if(result) {
      message.reply('You have the necessary permissions.'); // What happens if the user has the required permissions
    } else {
      message.reply('You do not have the necessary permissions.'); // What happens if the user does not have the required permissions
    }

    Depending on the result of the permission check, we send a reply to the user. If they have the necessary permissions, they are informed; otherwise, they are notified that they lack the required permissions.

  5. Final Code:

    const { newCommand, checkUserPerms } = require('mvk-project');
    
    newCommand({
      name: 'test-command',
      code: async function (message) {
        const result = await checkUserPerms({
          user: message.author.id, 
          permissions: ['ADMINISTRATOR', 'MANAGE_GUILD'], 
          guildId: message.guild.id
        });
    
        if(result) {
          message.reply('You have the necessary permissions.'); // What happens if the user has the required permissions
        } else {
          message.reply('You do not have the necessary permissions.'); // What happens if the user does not have the required permissions
        }
      }
    });

Permission Options:

The checkUserPerms function allows you to verify the following permissions:

Permission NameDescription

ADMINISTRATOR

Grants all permissions and overrides any specific permissions.

MANAGE_GUILD

Allows management and configuration of the guild (server).

KICK_MEMBERS

Allows kicking members from the guild.

BAN_MEMBERS

Allows banning members from the guild.

MANAGE_CHANNELS

Allows management of channels in the guild.

MANAGE_MESSAGES

Allows management and deletion of messages.

MUTE_MEMBERS

Allows muting members in voice channels.

DEAFEN_MEMBERS

Allows deafening members in voice channels.

MOVE_MEMBERS

Allows moving members between voice channels.

MANAGE_ROLES

Allows management of roles in the guild.

MANAGE_WEBHOOKS

Allows management of webhooks in the guild.

MANAGE_NICKNAMES

Allows changing and managing nicknames.

MANAGE_EMOJIS_AND_STICKERS

Allows management of emojis and stickers.

MANAGE_THREADS

Allows management of threads in channels.

Each permission name corresponds to a specific action or set of actions that a user can perform within the guild, ensuring that only users with the necessary authority can execute certain commands or tasks.

Last updated