From 77aa07e2515fa480531c8e4be1ceb7d26ca7550f Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 31 Mar 2022 01:26:25 +0300 Subject: [PATCH] more versatile command option definitions --- .../interfaces/commands/SlashCommand.js | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/structure/interfaces/commands/SlashCommand.js b/src/structure/interfaces/commands/SlashCommand.js index e81eb90..ab4c4fe 100644 --- a/src/structure/interfaces/commands/SlashCommand.js +++ b/src/structure/interfaces/commands/SlashCommand.js @@ -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; }