diff --git a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js index 6449e684d..5449c4e18 100644 --- a/packages/discord.js/src/structures/CommandInteractionOptionResolver.js +++ b/packages/discord.js/src/structures/CommandInteractionOptionResolver.js @@ -60,9 +60,9 @@ class CommandInteractionOptionResolver { /** * The interaction resolved data * @name CommandInteractionOptionResolver#resolved - * @type {Readonly} + * @type {?Readonly} */ - Object.defineProperty(this, 'resolved', { value: Object.freeze(resolved) }); + Object.defineProperty(this, 'resolved', { value: resolved ? Object.freeze(resolved) : null }); } /** @@ -256,10 +256,19 @@ class CommandInteractionOptionResolver { return option?.message ?? null; } + /** + * The full autocomplete option object. + * @typedef {Object} AutocompleteOption + * @property {string} name The name of the option + * @property {ApplicationCommandOptionType} type The type of the application command option + * @property {string|number} value The value of the option + * @property {boolean} focused Whether this option is currently in focus for autocomplete + */ + /** * Gets the focused option. * @param {boolean} [getFull=false] Whether to get the full option object - * @returns {string|number|ApplicationCommandOptionChoice} + * @returns {string|number|AutocompleteOption} * The value of the option, or the whole option if getFull is true */ getFocused(getFull = false) { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 65a790c55..9e15e20be 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -935,7 +935,10 @@ export class AutocompleteInteraction exten public commandName: string; public commandType: ApplicationCommandType.ChatInput; public responded: boolean; - public options: Omit, 'getMessage'>; + public options: Omit< + CommandInteractionOptionResolver, + 'getMessage' | 'getUser' | 'getAttachment' | 'getChannel' | 'getMember' | 'getMentionable' | 'getRole' + >; public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>; public inCachedGuild(): this is AutocompleteInteraction<'cached'>; public inRawGuild(): this is AutocompleteInteraction<'raw'>; @@ -946,7 +949,7 @@ export class CommandInteractionOptionResolver[]; - public readonly resolved: Readonly>; + public readonly resolved: Readonly> | null; private _group: string | null; private _hoistedOptions: CommandInteractionOption[]; private _subcommand: string | null; @@ -1000,7 +1003,7 @@ export class CommandInteractionOptionResolver['member' | 'role' | 'user']> | null; public getMessage(name: string, required: true): NonNullable['message']>; public getMessage(name: string, required?: boolean): NonNullable['message']> | null; - public getFocused(getFull: true): ApplicationCommandOptionChoiceData; + public getFocused(getFull: true): AutocompleteOption; public getFocused(getFull?: boolean): string | number; } @@ -4032,6 +4035,8 @@ export interface CommandInteractionResolvedData; } +export type AutocompleteOption = Pick; + export declare const Colors: { Default: 0x000000; White: 0xffffff;