commandbot
Version:
A framework that helps you create your own Discord bot easier.
62 lines (61 loc) • 2.83 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PermissionGuildCommand = void 0;
const PermissionCommand_js_1 = require("./PermissionCommand.js");
/**
* Guild-scoped executable command with permissions attached
* @class
* @extends {PermissionCommand}
* @implements {GuildCommand}
*/
class PermissionGuildCommand extends PermissionCommand_js_1.PermissionCommand {
/**
* Guild-scoped, executable, permissions command constructor
* @constructor
* @param {CommandManager} manager - command manager attached to this command
* @param {CommandType} type - command type
* @param {PermissionGuildCommandInit} options - command initialization options
*/
constructor(manager, type, options) {
var _a;
super(manager, type, {
name: options.name,
announceSuccess: options.announceSuccess,
default_permission: options.default_permission,
permissions: options.permissions,
ephemeral: options.ephemeral,
function: options.function,
});
this.guilds = options.guilds;
this.dm = (_a = options.dm) !== null && _a !== void 0 ? _a : true;
}
/**
* Invoke the command
* @param {InputManager} input - input data
* @returns {Promise<void>}
* @public
* @async
*/
start(input) {
const _super = Object.create(null, {
start: { get: () => super.start }
});
return __awaiter(this, void 0, void 0, function* () {
if (!input.interaction.guild && !this.dm)
throw new Error(`Command "${this.name}" is only available inside a guild.`);
if (this.guilds && this.guilds.length > 0 && !this.guilds.find((id) => { var _a; return id === ((_a = input.interaction.guild) === null || _a === void 0 ? void 0 : _a.id); }))
throw new Error(`Command "${this.name}" is not available.`);
yield _super.start.call(this, input);
});
}
}
exports.PermissionGuildCommand = PermissionGuildCommand;