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; }