@dexare/slash-create
Version:
A Dexare module that uses slash-create to make slash commands
50 lines (49 loc) • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const dexare_1 = require("dexare");
class SlashableDexareCommand extends dexare_1.DexareCommand {
constructor(client, opts, slashOpts) {
super(client, opts);
const slashOptions = Object.assign({}, slashOpts);
if (!slashOptions.name)
slashOptions.name = opts.name;
if (slashOpts.guildIDs)
slashOptions.guildIDs =
typeof slashOpts.guildIDs == 'string' ? [slashOpts.guildIDs] : slashOpts.guildIDs;
else
slashOpts.guildIDs = [];
slashOptions.unknown = slashOpts.unknown || false;
slashOptions.deferEphemeral = slashOpts.deferEphemeral || false;
slashOptions.defaultPermission =
typeof slashOpts.defaultPermission === 'boolean' ? slashOpts.defaultPermission : true;
this.slashOptions = slashOptions;
this.filePath = __filename;
}
get slashKeyName() {
const prefix = this.slashOptions.guildIDs ? this.slashOptions.guildIDs.join(',') : 'global';
return `${prefix}:${this.slashOptions.name}`;
}
async slashRun(ctx) {
throw new Error(`${this.constructor.name} doesn't have a run() method.`);
}
slashOnError(err, ctx) {
if (!ctx.expired && !ctx.initiallyResponded)
return ctx.send('An error occurred while running the command.', { ephemeral: true });
}
slashFinalize(response, ctx) {
if (!response && !ctx.initiallyResponded)
return;
if (typeof response === 'string' ||
(response && response.constructor && response.constructor.name === 'Object'))
return ctx.send(response);
}
get slashCommandJSON() {
return {
name: this.slashOptions.name,
description: this.slashOptions.description,
default_permission: this.slashOptions.defaultPermission,
...(this.slashOptions.options ? { options: this.slashOptions.options } : {})
};
}
}
exports.default = SlashableDexareCommand;