mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(CommandInteractionOptionResolver): Handle autocompletion interactions (#8058)
This commit is contained in:
@@ -60,9 +60,9 @@ class CommandInteractionOptionResolver {
|
||||
/**
|
||||
* The interaction resolved data
|
||||
* @name CommandInteractionOptionResolver#resolved
|
||||
* @type {Readonly<CommandInteractionResolvedData>}
|
||||
* @type {?Readonly<CommandInteractionResolvedData>}
|
||||
*/
|
||||
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) {
|
||||
|
||||
11
packages/discord.js/typings/index.d.ts
vendored
11
packages/discord.js/typings/index.d.ts
vendored
@@ -935,7 +935,10 @@ export class AutocompleteInteraction<Cached extends CacheType = CacheType> exten
|
||||
public commandName: string;
|
||||
public commandType: ApplicationCommandType.ChatInput;
|
||||
public responded: boolean;
|
||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
||||
public options: Omit<
|
||||
CommandInteractionOptionResolver<Cached>,
|
||||
'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<Cached extends CacheType = CacheTy
|
||||
private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData);
|
||||
public readonly client: Client;
|
||||
public readonly data: readonly CommandInteractionOption<Cached>[];
|
||||
public readonly resolved: Readonly<CommandInteractionResolvedData<Cached>>;
|
||||
public readonly resolved: Readonly<CommandInteractionResolvedData<Cached>> | null;
|
||||
private _group: string | null;
|
||||
private _hoistedOptions: CommandInteractionOption<Cached>[];
|
||||
private _subcommand: string | null;
|
||||
@@ -1000,7 +1003,7 @@ export class CommandInteractionOptionResolver<Cached extends CacheType = CacheTy
|
||||
): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']> | null;
|
||||
public getMessage(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['message']>;
|
||||
public getMessage(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['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<Cached extends CacheType = Cache
|
||||
attachments?: Collection<Snowflake, Attachment>;
|
||||
}
|
||||
|
||||
export type AutocompleteOption = Pick<CommandInteractionOption, 'name' | 'type' | 'value' | 'focused'>;
|
||||
|
||||
export declare const Colors: {
|
||||
Default: 0x000000;
|
||||
White: 0xffffff;
|
||||
|
||||
Reference in New Issue
Block a user