Downgrade to v13

[vi] cảm giác đau khổ
This commit is contained in:
March 7th
2022-03-24 17:55:32 +07:00
parent 9596b1a210
commit 7dfdef46a5
218 changed files with 8584 additions and 9108 deletions

View File

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