more versatile command option definitions
This commit is contained in:
parent
2dd3def245
commit
77aa07e251
@ -2,6 +2,7 @@ const Command = require('./Command.js');
|
||||
const { Commands: CommandsConstant } = require('../../../constants/');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const DiscordClient = require('../../DiscordClient.js');
|
||||
const CommandOption = require('../CommandOption.js');
|
||||
|
||||
class SlashCommand extends Command {
|
||||
|
||||
@ -15,8 +16,8 @@ class SlashCommand extends Command {
|
||||
if (!options) return null;
|
||||
if (!options.description?.length) throw new Error(`Slash commands MUST have a description: ${options.name}`);
|
||||
|
||||
super(client, {
|
||||
name: options.name,
|
||||
/*
|
||||
name: options.name,
|
||||
module: options.module,
|
||||
description: options.description,
|
||||
tags: options.tags,
|
||||
@ -25,12 +26,29 @@ class SlashCommand extends Command {
|
||||
archivable: options.archivable,
|
||||
disabled: options.disabled,
|
||||
guarded: options.guarded,
|
||||
showUsage: options.showUsage,
|
||||
showUsage: options.showUsage
|
||||
*/
|
||||
super(client, {
|
||||
...options,
|
||||
slash: true
|
||||
});
|
||||
|
||||
this.options = [];
|
||||
if(options.options) for (const opt of options.options) {
|
||||
if (opt instanceof CommandOption) this.options.push(opt);
|
||||
else if (opt.name instanceof Array) {
|
||||
// Allows easy templating of subcommands that share arguments
|
||||
const { name: names, description, ...opts } = opt;
|
||||
for (const name of names) {
|
||||
let desc = description;
|
||||
if(description instanceof Array) desc = description[names.indexOf(name)] || 'Missing description';
|
||||
this.options.push(new CommandOption({ name, description: desc, ...opts }));
|
||||
}
|
||||
} else this.options.push(new CommandOption(opt));
|
||||
}
|
||||
|
||||
this.type = Object.keys(CommandsConstant.ApplicationCommandTypes).includes(options.type) ? options.type : 'CHAT_INPUT';
|
||||
this.options = options.options || [];
|
||||
// this.options = options.options || [];
|
||||
this.defaultPermission = options.defaultPermission || true;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user