fixing up cmd handler to work with subcommands
This commit is contained in:
parent
9ea73581c0
commit
ed62fbfc43
@ -81,25 +81,34 @@ class CommandHandler extends Observer {
|
||||
|
||||
}
|
||||
|
||||
async _parseInteraction(thing) {
|
||||
/**
|
||||
* @param {InteractionWrapper} interaction
|
||||
*/
|
||||
async _parseInteraction(interaction) {
|
||||
|
||||
const { command, interaction } = thing;
|
||||
const { command, subcommand } = interaction;
|
||||
|
||||
if(!interaction.guild && command.guildOnly) {
|
||||
return thing.reply({ template: { index: 'O_COMMANDHANDLER_GUILDONLY' }, emoji: 'failure', ephemeral: true });
|
||||
return interaction.reply({ template: { index: 'O_COMMANDHANDLER_GUILDONLY' }, emoji: 'failure', ephemeral: true });
|
||||
}
|
||||
|
||||
let error = null;
|
||||
const options = {};
|
||||
// Find the option through the subcommand incase the subcommands have options with the same name
|
||||
const _subcommand = command.subcommand(subcommand.name);
|
||||
|
||||
// btw d.js already takes care of this, we don't need to do our own value parsing
|
||||
// unless we want to add support for custom stuff like time, but that sounds a bit unnecessary
|
||||
for(const option of interaction.options._hoistedOptions) {
|
||||
const matched = command.options.find((o) => o.name === option.name);
|
||||
if (!matched) continue;
|
||||
// unless we want to add support for custom stuff
|
||||
for (const option of interaction.optionsWithoutSubcommands) { // iterate through the received options
|
||||
|
||||
const matched = _subcommand.options.find((o) => o.name === option.name);
|
||||
if (!matched) { // Shouldn't occur but just in case
|
||||
this.client.logger.warn(`Command interaction option mismatch:\nCommand: ${command.name}\nReceived subcommand ${subcommand.name}`);
|
||||
continue;
|
||||
}
|
||||
const newOption = new CommandOption({ name: matched.name, type: matched.type, minimum: matched.minimum, maximum: matched.maximum, _rawValue: option.value });
|
||||
|
||||
const parsed = await this._parseOption(thing, newOption);
|
||||
const parsed = await this._parseOption(interaction, newOption);
|
||||
if(parsed.error) {
|
||||
error = {
|
||||
option: newOption,
|
||||
@ -192,9 +201,7 @@ class CommandHandler extends Observer {
|
||||
}
|
||||
};
|
||||
|
||||
const result = types[option.type](option._rawValue);
|
||||
if(result instanceof Promise) await result;
|
||||
return result;
|
||||
return types[option.type](option._rawValue);
|
||||
}
|
||||
|
||||
async _getCommand(message) {
|
||||
|
Loading…
Reference in New Issue
Block a user