fix(SendSlash): Mix SubGroupCommand and SubCommand

This commit is contained in:
March 7th 2022-08-17 17:48:22 +07:00
parent f675d2dd58
commit f996bf0fae

View File

@ -595,7 +595,7 @@ class ApplicationCommand extends Base {
*/ */
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
async sendSlashCommand(message, subCommandArray = [], options = []) { async sendSlashCommand(message, subCommandArray = [], options = []) {
// Todo: Refactor // Todo: Refactor [Done]
const buildError = (type, value, array, msg) => const buildError = (type, value, array, msg) =>
new Error(`Invalid ${type}: ${value} ${msg}\nList of ${type}:\n${array}`); new Error(`Invalid ${type}: ${value} ${msg}\nList of ${type}:\n${array}`);
// Check Options // Check Options
@ -727,13 +727,14 @@ class ApplicationCommand extends Base {
} }
return optionFormat; return optionFormat;
}; };
const parseSubCommand = async (subCommandName, options) => { const parseSubCommand = async (subCommandName, options, subGroup) => {
const subCommand = this.options.find(o => o.name == subCommandName && o.type == 'SUB_COMMAND'); const options_sub = subGroup ? subGroup.options : this.options;
const subCommand = options_sub.find(o => o.name == subCommandName && o.type == 'SUB_COMMAND');
if (!subCommand) { if (!subCommand) {
throw buildError( throw buildError(
'SubCommand', 'SubCommand',
subCommandName, subCommandName,
this.options.map((o, i) => ` #${i + 1} Name: ${o.name}`).join('\n'), options_sub.map((o, i) => ` #${i + 1} Name: ${o.name}`).join('\n'),
'is not a valid sub command', 'is not a valid sub command',
); );
} }
@ -763,7 +764,7 @@ class ApplicationCommand extends Base {
'is not a valid sub group command', 'is not a valid sub group command',
); );
} }
const data = await parseSubCommand(subName, options); const data = await parseSubCommand(subName, options, subGroup);
return { return {
type: ApplicationCommandOptionTypes[subGroup.type], type: ApplicationCommandOptionTypes[subGroup.type],
name: subGroup.name, name: subGroup.name,