mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
feat(CommandInteraction): add CommandInteractionOptionResolver (#6107)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
|
||||
const Interaction = require('./Interaction');
|
||||
const InteractionWebhook = require('./InteractionWebhook');
|
||||
const InteractionResponses = require('./interfaces/InteractionResponses');
|
||||
const Collection = require('../util/Collection');
|
||||
const { ApplicationCommandOptionTypes } = require('../util/Constants');
|
||||
|
||||
/**
|
||||
@@ -48,9 +48,12 @@ class CommandInteraction extends Interaction {
|
||||
|
||||
/**
|
||||
* The options passed to the command.
|
||||
* @type {Collection<string, CommandInteractionOption>}
|
||||
* @type {CommandInteractionOptionResolver}
|
||||
*/
|
||||
this.options = this._createOptionsCollection(data.data.options, data.data.resolved);
|
||||
this.options = new CommandInteractionOptionResolver(
|
||||
this.client,
|
||||
data.data.options?.map(option => this.transformOption(option, data.data.resolved)),
|
||||
);
|
||||
|
||||
/**
|
||||
* Whether this interaction has already been replied to
|
||||
@@ -108,7 +111,7 @@ class CommandInteraction extends Interaction {
|
||||
};
|
||||
|
||||
if ('value' in option) result.value = option.value;
|
||||
if ('options' in option) result.options = this._createOptionsCollection(option.options, resolved);
|
||||
if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved));
|
||||
|
||||
if (resolved) {
|
||||
const user = resolved.users?.[option.value];
|
||||
@@ -127,22 +130,6 @@ class CommandInteraction extends Interaction {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a collection of options from the received options array.
|
||||
* @param {APIApplicationCommandOption[]} options The received options
|
||||
* @param {APIApplicationCommandOptionResolved} resolved The resolved interaction data
|
||||
* @returns {Collection<string, CommandInteractionOption>}
|
||||
* @private
|
||||
*/
|
||||
_createOptionsCollection(options, resolved) {
|
||||
const optionsCollection = new Collection();
|
||||
if (typeof options === 'undefined') return optionsCollection;
|
||||
for (const option of options) {
|
||||
optionsCollection.set(option.name, this.transformOption(option, resolved));
|
||||
}
|
||||
return optionsCollection;
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by InteractionResponses
|
||||
/* eslint-disable no-empty-function */
|
||||
defer() {}
|
||||
|
||||
Reference in New Issue
Block a user