mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
feat: add support for autocomplete interactions (#6672)
Co-authored-by: Suneet Tipirneni <suneettipirneni@icloud.com>
This commit is contained in:
71
typings/index.d.ts
vendored
71
typings/index.d.ts
vendored
@@ -277,8 +277,20 @@ export type GuildCacheMessage<Cached extends CacheType> = CacheTypeReducer<
|
||||
>;
|
||||
|
||||
export abstract class BaseCommandInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
|
||||
public options: CommandInteractionOptionResolver<Cached>;
|
||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||
public options: Omit<
|
||||
CommandInteractionOptionResolver<Cached>,
|
||||
| 'getFocused'
|
||||
| 'getMentionable'
|
||||
| 'getRole'
|
||||
| 'getNumber'
|
||||
| 'getInteger'
|
||||
| 'getString'
|
||||
| 'getChannel'
|
||||
| 'getBoolean'
|
||||
| 'getSubcommandGroup'
|
||||
| 'getSubcommand'
|
||||
>;
|
||||
public channelId: Snowflake;
|
||||
public commandId: Snowflake;
|
||||
public commandName: string;
|
||||
@@ -589,10 +601,60 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
||||
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaitable<void>): this;
|
||||
}
|
||||
|
||||
export interface ApplicationCommandInteractionOptionResolver<Cached extends CacheType = CacheType>
|
||||
extends BaseCommandInteractionOptionResolver<Cached> {
|
||||
getSubcommand(required?: true): string;
|
||||
getSubcommand(required: boolean): string | null;
|
||||
getSubcommandGroup(required?: true): string;
|
||||
getSubcommandGroup(required: boolean): string | null;
|
||||
getBoolean(name: string, required: true): boolean;
|
||||
getBoolean(name: string, required?: boolean): boolean | null;
|
||||
getChannel(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['channel']>;
|
||||
getChannel(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['channel']> | null;
|
||||
getString(name: string, required: true): string;
|
||||
getString(name: string, required?: boolean): string | null;
|
||||
getInteger(name: string, required: true): number;
|
||||
getInteger(name: string, required?: boolean): number | null;
|
||||
getNumber(name: string, required: true): number;
|
||||
getNumber(name: string, required?: boolean): number | null;
|
||||
getUser(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['user']>;
|
||||
getUser(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['user']> | null;
|
||||
getMember(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['member']>;
|
||||
getMember(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['member']> | null;
|
||||
getRole(name: string, required: true): NonNullable<CommandInteractionOption<Cached>['role']>;
|
||||
getRole(name: string, required?: boolean): NonNullable<CommandInteractionOption<Cached>['role']> | null;
|
||||
getMentionable(
|
||||
name: string,
|
||||
required: true,
|
||||
): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']>;
|
||||
getMentionable(
|
||||
name: string,
|
||||
required?: boolean,
|
||||
): NonNullable<CommandInteractionOption<Cached>['member' | 'role' | 'user']> | null;
|
||||
}
|
||||
|
||||
export class CommandInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
|
||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage' | 'getFocused'>;
|
||||
public inGuild(): this is CommandInteraction<'present'> & this;
|
||||
public inCachedGuild(): this is CommandInteraction<'cached'> & this;
|
||||
public inRawGuild(): this is CommandInteraction<'raw'> & this;
|
||||
public toString(): string;
|
||||
}
|
||||
|
||||
export class AutocompleteInteraction<Cached extends CacheType = CacheType> extends Interaction<Cached> {
|
||||
public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null;
|
||||
public channelId: Snowflake;
|
||||
public commandId: Snowflake;
|
||||
public commandName: string;
|
||||
public responded: boolean;
|
||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
||||
public inGuild(): this is CommandInteraction<'present'> & this;
|
||||
public inCachedGuild(): this is CommandInteraction<'cached'> & this;
|
||||
public inRawGuild(): this is CommandInteraction<'raw'> & this;
|
||||
private transformOption(option: APIApplicationCommandOption): CommandInteractionOption;
|
||||
public respond(options: ApplicationCommandOptionChoice[]): Promise<void>;
|
||||
}
|
||||
|
||||
export class CommandInteractionOptionResolver<Cached extends CacheType = CacheType> {
|
||||
private constructor(client: Client, options: CommandInteractionOption[], resolved: CommandInteractionResolvedData);
|
||||
public readonly client: Client;
|
||||
@@ -647,7 +709,10 @@ 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): ApplicationCommandOptionChoice;
|
||||
public getFocused(getFull?: boolean): string | number;
|
||||
}
|
||||
|
||||
export class ContextMenuInteraction<Cached extends CacheType = CacheType> extends BaseCommandInteraction<Cached> {
|
||||
public targetId: Snowflake;
|
||||
public targetType: Exclude<ApplicationCommandType, 'CHAT_INPUT'>;
|
||||
@@ -1095,6 +1160,7 @@ export class Interaction<Cached extends CacheType = CacheType> extends Base {
|
||||
public isApplicationCommand(): this is BaseCommandInteraction<Cached>;
|
||||
public isButton(): this is ButtonInteraction<Cached>;
|
||||
public isCommand(): this is CommandInteraction<Cached>;
|
||||
public isAutocomplete(): this is AutocompleteInteraction;
|
||||
public isContextMenu(): this is ContextMenuInteraction<Cached>;
|
||||
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
|
||||
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
|
||||
@@ -3187,6 +3253,7 @@ export interface BaseApplicationCommandOptionsData {
|
||||
name: string;
|
||||
description: string;
|
||||
required?: boolean;
|
||||
autocomplete?: boolean;
|
||||
}
|
||||
|
||||
export interface UserApplicationCommandData extends BaseApplicationCommandData {
|
||||
@@ -3643,6 +3710,8 @@ export interface CommandInteractionOption<Cached extends CacheType = CacheType>
|
||||
name: string;
|
||||
type: ApplicationCommandOptionType;
|
||||
value?: string | number | boolean;
|
||||
focused?: boolean;
|
||||
autocomplete?: boolean;
|
||||
options?: CommandInteractionOption[];
|
||||
user?: User;
|
||||
member?: CacheTypeReducer<Cached, GuildMember, APIInteractionDataResolvedGuildMember>;
|
||||
|
||||
Reference in New Issue
Block a user