Downgrade to v13
[vi] cảm giác đau khổ
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const { InteractionResponseType, Routes } = require('discord-api-types/v9');
|
||||
const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
|
||||
const Interaction = require('./Interaction');
|
||||
const { InteractionResponseTypes, ApplicationCommandOptionTypes } = require('../util/Constants');
|
||||
|
||||
/**
|
||||
* Represents an autocomplete interaction.
|
||||
@@ -30,12 +30,6 @@ class AutocompleteInteraction extends Interaction {
|
||||
*/
|
||||
this.commandName = data.data.name;
|
||||
|
||||
/**
|
||||
* The invoked application command's type
|
||||
* @type {ApplicationCommandType.ChatInput}
|
||||
*/
|
||||
this.commandType = data.data.type;
|
||||
|
||||
/**
|
||||
* Whether this interaction has already received a response
|
||||
* @type {boolean}
|
||||
@@ -46,7 +40,10 @@ class AutocompleteInteraction extends Interaction {
|
||||
* The options passed to the command
|
||||
* @type {CommandInteractionOptionResolver}
|
||||
*/
|
||||
this.options = new CommandInteractionOptionResolver(this.client, data.data.options ?? []);
|
||||
this.options = new CommandInteractionOptionResolver(
|
||||
this.client,
|
||||
data.data.options?.map(option => this.transformOption(option, data.data.resolved)) ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +55,25 @@ class AutocompleteInteraction extends Interaction {
|
||||
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an option received from the API.
|
||||
* @param {APIApplicationCommandOption} option The received option
|
||||
* @returns {CommandInteractionOption}
|
||||
* @private
|
||||
*/
|
||||
transformOption(option) {
|
||||
const result = {
|
||||
name: option.name,
|
||||
type: ApplicationCommandOptionTypes[option.type],
|
||||
};
|
||||
|
||||
if ('value' in option) result.value = option.value;
|
||||
if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt));
|
||||
if ('focused' in option) result.focused = option.focused;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends results for the autocomplete of this interaction.
|
||||
* @param {ApplicationCommandOptionChoice[]} options The options for the autocomplete
|
||||
@@ -77,14 +93,14 @@ class AutocompleteInteraction extends Interaction {
|
||||
if (this.responded) throw new Error('INTERACTION_ALREADY_REPLIED');
|
||||
|
||||
await this.client.api.interactions(this.id, this.token).callback.post({
|
||||
body: {
|
||||
type: InteractionResponseType.ApplicationCommandAutocompleteResult,
|
||||
data: {
|
||||
type: InteractionResponseTypes.APPLICATION_COMMAND_AUTOCOMPLETE_RESULT,
|
||||
data: {
|
||||
choices: options,
|
||||
},
|
||||
},
|
||||
auth: false,
|
||||
})
|
||||
});
|
||||
this.responded = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user