Required Permissions

You may want your bot commands to be ran by users in a Discord Server with the required Server permissions or roles.

Permissions

When you set required permissions in the permission array, you can specify a String or PermissionFlagsBits enum. For PermissionFlagsBits enum, please read this documentation.

With that, let's add this option to our device command:

device.js
const { NoCliCommandType } = require("nocli-handler.js");
const { PermissionFlagsBits } = require("discord.js")

/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    description: "Asks what device you are using",
    type: NoCliCommandType.Slash,
    expectedArgs: '<device>',
    permissions: [PermissionFlagsBits.Administrator],
    minArgs: 1,
    maxArgs: 1,
    autocomplete: (interaction, command, args) => {
        return ["Desktop", "Laptop", "Phone", "Tablet"]
    },
    callback: ({ client, interaction, args, text }) => {
        return `You chose ${args.join(' ')}`;
    }
}

module.exports = Command;

End Result

Last updated