UNPKG

commandbot

Version:

A framework that helps you create your own Discord bot easier.

50 lines (49 loc) 1.61 kB
import { PermissionsError } from "../../errors.js"; import { CommandPermissions } from "../../structures/CommandPermissions.js"; import { FunctionCommand } from "./FunctionCommand.js"; /** * Executable command with attached permission system * @class * @extends {FunctionCommand} */ export class PermissionCommand extends FunctionCommand { /** * Object containing check functions and permission bitfields * @type {CommandPermissions} * @public * @readonly */ permissions; /** * Constructor of command with attached permissions * @constructor * @param {CommandManager} manager - command manager attached to this command * @param {CommandType} type - command type * @param {PermissionCommandInit} options - command initalization options */ constructor(manager, type, options) { super(manager, type, { name: options.name, announceSuccess: options.announceSuccess, default_permission: options.default_permission, ephemeral: options.ephemeral, function: options.function, }); this.permissions = new CommandPermissions(this, options.permissions); } /** * Invoke the command * @param {InputManager} input - input data * @returns {Promise<void>} * @public * @async */ async start(input) { if (this.permissions.check(input.interaction)) { await super.start(input); } else { throw new PermissionsError(this); } } }