From 3b9320dbf2cbbae7db44f00e8deaf336ab052e8b Mon Sep 17 00:00:00 2001 From: Suneet Tipirneni <77477100+suneettipirneni@users.noreply.github.com> Date: Fri, 29 Oct 2021 09:02:42 -0400 Subject: [PATCH] feat(Interactions): add autocomplete api types (#205) --- .../_applicationCommands/chatInput.ts | 47 ++++++++++++------ .../payloads/v8/_interactions/autocomplete.ts | 6 +++ deno/payloads/v8/_interactions/responses.ts | 18 ++++++- deno/payloads/v8/interactions.ts | 7 ++- .../_applicationCommands/chatInput.ts | 49 +++++++++++++------ .../payloads/v9/_interactions/autocomplete.ts | 6 +++ deno/payloads/v9/_interactions/responses.ts | 18 ++++++- deno/payloads/v9/interactions.ts | 7 ++- deno/rest/v8/interactions.ts | 4 ++ deno/rest/v9/interactions.ts | 4 ++ .../_applicationCommands/chatInput.ts | 47 ++++++++++++------ payloads/v8/_interactions/autocomplete.ts | 6 +++ payloads/v8/_interactions/responses.ts | 18 ++++++- payloads/v8/interactions.ts | 7 ++- .../_applicationCommands/chatInput.ts | 49 +++++++++++++------ payloads/v9/_interactions/autocomplete.ts | 6 +++ payloads/v9/_interactions/responses.ts | 18 ++++++- payloads/v9/interactions.ts | 7 ++- rest/v8/interactions.ts | 4 ++ rest/v9/interactions.ts | 4 ++ 20 files changed, 266 insertions(+), 66 deletions(-) create mode 100644 deno/payloads/v8/_interactions/autocomplete.ts create mode 100644 deno/payloads/v9/_interactions/autocomplete.ts create mode 100644 payloads/v8/_interactions/autocomplete.ts create mode 100644 payloads/v9/_interactions/autocomplete.ts diff --git a/deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts b/deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts index a50a9880..7b94cd4c 100644 --- a/deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts +++ b/deno/payloads/v8/_interactions/_applicationCommands/chatInput.ts @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase { description: string; default?: boolean; required?: boolean; + autocomplete?: never; } /** @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase { export type APIApplicationCommandOption = | APIApplicationCommandArgumentOptions | APIApplicationCommandSubCommandOptions + | APIApplicationCommandOptionBase | APIApplicationCommandChannelOptions - | APIApplicationCommandOptionBase; + | APIApplicationCommandAutocompleteOptions; /** * This type is exported as a way to make it stricter for you when you're writing your commands @@ -46,12 +48,29 @@ export interface APIApplicationCommandSubCommandOptions extends Omit { +export interface APIApplicationCommandArgumentOptions + extends Omit { type: | ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; choices?: APIApplicationCommandOptionChoice[]; + autocomplete?: false; +} + +/** + * This type is exported as a way to make it stricter for you when you're writing your commands + * + * In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array, + * but they can a `autocomplete` field where it's set to `true` + */ +export interface APIApplicationCommandAutocompleteOptions + extends Omit { + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Integer + | ApplicationCommandOptionType.Number; + autocomplete: true; } /** @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues = | ApplicationCommandInteractionDataOptionNumber | ApplicationCommandInteractionDataOptionBoolean; -export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase< - ApplicationCommandOptionType.String, - string ->; +export interface ApplicationCommandInteractionDataOptionString + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase< ApplicationCommandOptionType.Role, @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData Snowflake >; -export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase< - ApplicationCommandOptionType.Integer, - number ->; +export interface ApplicationCommandInteractionDataOptionInteger + extends InteractionDataOptionBase { + focused?: boolean; +} -export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase< - ApplicationCommandOptionType.Number, - number ->; +export interface ApplicationCommandInteractionDataOptionNumber + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase< ApplicationCommandOptionType.Boolean, diff --git a/deno/payloads/v8/_interactions/autocomplete.ts b/deno/payloads/v8/_interactions/autocomplete.ts new file mode 100644 index 00000000..c71587e9 --- /dev/null +++ b/deno/payloads/v8/_interactions/autocomplete.ts @@ -0,0 +1,6 @@ +import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../mod.ts'; + +export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction< + InteractionType.ApplicationCommandAutocomplete, + APIApplicationCommandInteractionData +>; diff --git a/deno/payloads/v8/_interactions/responses.ts b/deno/payloads/v8/_interactions/responses.ts index d3e3db3d..4edff842 100644 --- a/deno/payloads/v8/_interactions/responses.ts +++ b/deno/payloads/v8/_interactions/responses.ts @@ -1,5 +1,6 @@ import type { MessageFlags } from '../mod.ts'; import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8.ts'; +import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type @@ -8,6 +9,7 @@ export enum InteractionType { Ping = 1, ApplicationCommand, MessageComponent, + ApplicationCommandAutocomplete, } /** @@ -18,12 +20,18 @@ export type APIInteractionResponse = | APIInteractionResponseChannelMessageWithSource | APIInteractionResponseDeferredChannelMessageWithSource | APIInteractionResponseDeferredMessageUpdate - | APIInteractionResponseUpdateMessage; + | APIInteractionResponseUpdateMessage + | APIApplicationCommandAutocompleteResponse; export interface APIInteractionResponsePong { type: InteractionResponseType.Pong; } +export interface APIApplicationCommandAutocompleteResponse { + type: InteractionResponseType.ApplicationCommandAutocompleteResult; + data: APICommandAutocompleteInteractionResponseCallbackData; +} + export interface APIInteractionResponseChannelMessageWithSource { type: InteractionResponseType.ChannelMessageWithSource; data: APIInteractionResponseCallbackData; @@ -67,6 +75,10 @@ export enum InteractionResponseType { * ACK a button interaction and edit the message to which the button was attached */ UpdateMessage, + /** + * For autocomplete interactions + */ + ApplicationCommandAutocompleteResult, } /** @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit< RESTPostAPIWebhookWithTokenJSONBody, 'username' | 'avatar_url' > & { flags?: MessageFlags }; + +export interface APICommandAutocompleteInteractionResponseCallbackData { + choices?: APIApplicationCommandOptionChoice[]; +} diff --git a/deno/payloads/v8/interactions.ts b/deno/payloads/v8/interactions.ts index f88a00cb..e2903adc 100644 --- a/deno/payloads/v8/interactions.ts +++ b/deno/payloads/v8/interactions.ts @@ -9,6 +9,7 @@ import type { APIApplicationCommandGuildInteraction, APIApplicationCommandInteraction, } from './_interactions/applicationCommands.ts'; +import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts'; export * from './_interactions/base.ts'; export * from './_interactions/messageComponents.ts'; @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object */ -export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction; +export type APIInteraction = + | APIPingInteraction + | APIApplicationCommandInteraction + | APIMessageComponentInteraction + | APIApplicationCommandAutocompleteInteraction; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object diff --git a/deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts b/deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts index a50a9880..ad9eca09 100644 --- a/deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts +++ b/deno/payloads/v9/_interactions/_applicationCommands/chatInput.ts @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase { description: string; default?: boolean; required?: boolean; + autocomplete?: never; } /** @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase { export type APIApplicationCommandOption = | APIApplicationCommandArgumentOptions | APIApplicationCommandSubCommandOptions + | APIApplicationCommandOptionBase | APIApplicationCommandChannelOptions - | APIApplicationCommandOptionBase; + | APIApplicationCommandAutocompleteOptions; /** * This type is exported as a way to make it stricter for you when you're writing your commands @@ -44,14 +46,31 @@ export interface APIApplicationCommandSubCommandOptions extends Omit { +export interface APIApplicationCommandArgumentOptions + extends Omit { type: | ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; choices?: APIApplicationCommandOptionChoice[]; + autocomplete?: false; +} + +/** + * This type is exported as a way to make it stricter for you when you're writing your commands + * + * In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array, + * but they can a `autocomplete` field where it's set to `true` + */ +export interface APIApplicationCommandAutocompleteOptions + extends Omit { + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Integer + | ApplicationCommandOptionType.Number; + autocomplete: true; } /** @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues = | ApplicationCommandInteractionDataOptionNumber | ApplicationCommandInteractionDataOptionBoolean; -export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase< - ApplicationCommandOptionType.String, - string ->; +export interface ApplicationCommandInteractionDataOptionString + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase< ApplicationCommandOptionType.Role, @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData Snowflake >; -export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase< - ApplicationCommandOptionType.Integer, - number ->; +export interface ApplicationCommandInteractionDataOptionInteger + extends InteractionDataOptionBase { + focused?: boolean; +} -export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase< - ApplicationCommandOptionType.Number, - number ->; +export interface ApplicationCommandInteractionDataOptionNumber + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase< ApplicationCommandOptionType.Boolean, diff --git a/deno/payloads/v9/_interactions/autocomplete.ts b/deno/payloads/v9/_interactions/autocomplete.ts new file mode 100644 index 00000000..c71587e9 --- /dev/null +++ b/deno/payloads/v9/_interactions/autocomplete.ts @@ -0,0 +1,6 @@ +import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../mod.ts'; + +export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction< + InteractionType.ApplicationCommandAutocomplete, + APIApplicationCommandInteractionData +>; diff --git a/deno/payloads/v9/_interactions/responses.ts b/deno/payloads/v9/_interactions/responses.ts index 128677d4..a4655fb5 100644 --- a/deno/payloads/v9/_interactions/responses.ts +++ b/deno/payloads/v9/_interactions/responses.ts @@ -1,5 +1,6 @@ import type { MessageFlags } from '../mod.ts'; import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9.ts'; +import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type @@ -8,6 +9,7 @@ export enum InteractionType { Ping = 1, ApplicationCommand, MessageComponent, + ApplicationCommandAutocomplete, } /** @@ -18,12 +20,18 @@ export type APIInteractionResponse = | APIInteractionResponseChannelMessageWithSource | APIInteractionResponseDeferredChannelMessageWithSource | APIInteractionResponseDeferredMessageUpdate - | APIInteractionResponseUpdateMessage; + | APIInteractionResponseUpdateMessage + | APIApplicationCommandAutocompleteResponse; export interface APIInteractionResponsePong { type: InteractionResponseType.Pong; } +export interface APIApplicationCommandAutocompleteResponse { + type: InteractionResponseType.ApplicationCommandAutocompleteResult; + data: APICommandAutocompleteInteractionResponseCallbackData; +} + export interface APIInteractionResponseChannelMessageWithSource { type: InteractionResponseType.ChannelMessageWithSource; data: APIInteractionResponseCallbackData; @@ -67,6 +75,10 @@ export enum InteractionResponseType { * ACK a button interaction and edit the message to which the button was attached */ UpdateMessage, + /** + * For autocomplete interactions + */ + ApplicationCommandAutocompleteResult, } /** @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit< RESTPostAPIWebhookWithTokenJSONBody, 'username' | 'avatar_url' > & { flags?: MessageFlags }; + +export interface APICommandAutocompleteInteractionResponseCallbackData { + choices?: APIApplicationCommandOptionChoice[]; +} diff --git a/deno/payloads/v9/interactions.ts b/deno/payloads/v9/interactions.ts index f88a00cb..e2903adc 100644 --- a/deno/payloads/v9/interactions.ts +++ b/deno/payloads/v9/interactions.ts @@ -9,6 +9,7 @@ import type { APIApplicationCommandGuildInteraction, APIApplicationCommandInteraction, } from './_interactions/applicationCommands.ts'; +import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete.ts'; export * from './_interactions/base.ts'; export * from './_interactions/messageComponents.ts'; @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands.ts'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object */ -export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction; +export type APIInteraction = + | APIPingInteraction + | APIApplicationCommandInteraction + | APIMessageComponentInteraction + | APIApplicationCommandAutocompleteInteraction; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object diff --git a/deno/rest/v8/interactions.ts b/deno/rest/v8/interactions.ts index bd98a0c6..3707de38 100644 --- a/deno/rest/v8/interactions.ts +++ b/deno/rest/v8/interactions.ts @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit< */ export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody { type?: ApplicationCommandType.ChatInput; + /** + * Whether this application command option should be autocompleted + */ + autocomplete?: boolean; description: string; } diff --git a/deno/rest/v9/interactions.ts b/deno/rest/v9/interactions.ts index 12d3954d..1d7e2c37 100644 --- a/deno/rest/v9/interactions.ts +++ b/deno/rest/v9/interactions.ts @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit< */ export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody { type?: ApplicationCommandType.ChatInput; + /** + * Whether this application command option should be autocompleted + */ + autocomplete?: boolean; description: string; } diff --git a/payloads/v8/_interactions/_applicationCommands/chatInput.ts b/payloads/v8/_interactions/_applicationCommands/chatInput.ts index bba25220..e01990d2 100644 --- a/payloads/v8/_interactions/_applicationCommands/chatInput.ts +++ b/payloads/v8/_interactions/_applicationCommands/chatInput.ts @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase { description: string; default?: boolean; required?: boolean; + autocomplete?: never; } /** @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase { export type APIApplicationCommandOption = | APIApplicationCommandArgumentOptions | APIApplicationCommandSubCommandOptions + | APIApplicationCommandOptionBase | APIApplicationCommandChannelOptions - | APIApplicationCommandOptionBase; + | APIApplicationCommandAutocompleteOptions; /** * This type is exported as a way to make it stricter for you when you're writing your commands @@ -46,12 +48,29 @@ export interface APIApplicationCommandSubCommandOptions extends Omit { +export interface APIApplicationCommandArgumentOptions + extends Omit { type: | ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; choices?: APIApplicationCommandOptionChoice[]; + autocomplete?: false; +} + +/** + * This type is exported as a way to make it stricter for you when you're writing your commands + * + * In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array, + * but they can a `autocomplete` field where it's set to `true` + */ +export interface APIApplicationCommandAutocompleteOptions + extends Omit { + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Integer + | ApplicationCommandOptionType.Number; + autocomplete: true; } /** @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues = | ApplicationCommandInteractionDataOptionNumber | ApplicationCommandInteractionDataOptionBoolean; -export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase< - ApplicationCommandOptionType.String, - string ->; +export interface ApplicationCommandInteractionDataOptionString + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase< ApplicationCommandOptionType.Role, @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData Snowflake >; -export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase< - ApplicationCommandOptionType.Integer, - number ->; +export interface ApplicationCommandInteractionDataOptionInteger + extends InteractionDataOptionBase { + focused?: boolean; +} -export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase< - ApplicationCommandOptionType.Number, - number ->; +export interface ApplicationCommandInteractionDataOptionNumber + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase< ApplicationCommandOptionType.Boolean, diff --git a/payloads/v8/_interactions/autocomplete.ts b/payloads/v8/_interactions/autocomplete.ts new file mode 100644 index 00000000..66e99a08 --- /dev/null +++ b/payloads/v8/_interactions/autocomplete.ts @@ -0,0 +1,6 @@ +import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../index'; + +export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction< + InteractionType.ApplicationCommandAutocomplete, + APIApplicationCommandInteractionData +>; diff --git a/payloads/v8/_interactions/responses.ts b/payloads/v8/_interactions/responses.ts index 44475d97..91024ba6 100644 --- a/payloads/v8/_interactions/responses.ts +++ b/payloads/v8/_interactions/responses.ts @@ -1,5 +1,6 @@ import type { MessageFlags } from '../index'; import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8'; +import type { APIApplicationCommandOptionChoice } from './applicationCommands'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type @@ -8,6 +9,7 @@ export const enum InteractionType { Ping = 1, ApplicationCommand, MessageComponent, + ApplicationCommandAutocomplete, } /** @@ -18,12 +20,18 @@ export type APIInteractionResponse = | APIInteractionResponseChannelMessageWithSource | APIInteractionResponseDeferredChannelMessageWithSource | APIInteractionResponseDeferredMessageUpdate - | APIInteractionResponseUpdateMessage; + | APIInteractionResponseUpdateMessage + | APIApplicationCommandAutocompleteResponse; export interface APIInteractionResponsePong { type: InteractionResponseType.Pong; } +export interface APIApplicationCommandAutocompleteResponse { + type: InteractionResponseType.ApplicationCommandAutocompleteResult; + data: APICommandAutocompleteInteractionResponseCallbackData; +} + export interface APIInteractionResponseChannelMessageWithSource { type: InteractionResponseType.ChannelMessageWithSource; data: APIInteractionResponseCallbackData; @@ -67,6 +75,10 @@ export const enum InteractionResponseType { * ACK a button interaction and edit the message to which the button was attached */ UpdateMessage, + /** + * For autocomplete interactions + */ + ApplicationCommandAutocompleteResult, } /** @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit< RESTPostAPIWebhookWithTokenJSONBody, 'username' | 'avatar_url' > & { flags?: MessageFlags }; + +export interface APICommandAutocompleteInteractionResponseCallbackData { + choices?: APIApplicationCommandOptionChoice[]; +} diff --git a/payloads/v8/interactions.ts b/payloads/v8/interactions.ts index 23d29d6a..e1ef9072 100644 --- a/payloads/v8/interactions.ts +++ b/payloads/v8/interactions.ts @@ -9,6 +9,7 @@ import type { APIApplicationCommandGuildInteraction, APIApplicationCommandInteraction, } from './_interactions/applicationCommands'; +import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete'; export * from './_interactions/base'; export * from './_interactions/messageComponents'; @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object */ -export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction; +export type APIInteraction = + | APIPingInteraction + | APIApplicationCommandInteraction + | APIMessageComponentInteraction + | APIApplicationCommandAutocompleteInteraction; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object diff --git a/payloads/v9/_interactions/_applicationCommands/chatInput.ts b/payloads/v9/_interactions/_applicationCommands/chatInput.ts index bba25220..f26602ac 100644 --- a/payloads/v9/_interactions/_applicationCommands/chatInput.ts +++ b/payloads/v9/_interactions/_applicationCommands/chatInput.ts @@ -19,6 +19,7 @@ interface APIApplicationCommandOptionBase { description: string; default?: boolean; required?: boolean; + autocomplete?: never; } /** @@ -27,8 +28,9 @@ interface APIApplicationCommandOptionBase { export type APIApplicationCommandOption = | APIApplicationCommandArgumentOptions | APIApplicationCommandSubCommandOptions + | APIApplicationCommandOptionBase | APIApplicationCommandChannelOptions - | APIApplicationCommandOptionBase; + | APIApplicationCommandAutocompleteOptions; /** * This type is exported as a way to make it stricter for you when you're writing your commands @@ -44,14 +46,31 @@ export interface APIApplicationCommandSubCommandOptions extends Omit { +export interface APIApplicationCommandArgumentOptions + extends Omit { type: | ApplicationCommandOptionType.String | ApplicationCommandOptionType.Integer | ApplicationCommandOptionType.Number; choices?: APIApplicationCommandOptionChoice[]; + autocomplete?: false; +} + +/** + * This type is exported as a way to make it stricter for you when you're writing your commands + * + * In contrast to `APIApplicationCommandArgumentOptions`, these types cannot have an `choices` array, + * but they can a `autocomplete` field where it's set to `true` + */ +export interface APIApplicationCommandAutocompleteOptions + extends Omit { + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Integer + | ApplicationCommandOptionType.Number; + autocomplete: true; } /** @@ -119,10 +138,10 @@ export type APIApplicationCommandInteractionDataOptionWithValues = | ApplicationCommandInteractionDataOptionNumber | ApplicationCommandInteractionDataOptionBoolean; -export type ApplicationCommandInteractionDataOptionString = InteractionDataOptionBase< - ApplicationCommandOptionType.String, - string ->; +export interface ApplicationCommandInteractionDataOptionString + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionRole = InteractionDataOptionBase< ApplicationCommandOptionType.Role, @@ -144,15 +163,15 @@ export type ApplicationCommandInteractionDataOptionMentionable = InteractionData Snowflake >; -export type ApplicationCommandInteractionDataOptionInteger = InteractionDataOptionBase< - ApplicationCommandOptionType.Integer, - number ->; +export interface ApplicationCommandInteractionDataOptionInteger + extends InteractionDataOptionBase { + focused?: boolean; +} -export type ApplicationCommandInteractionDataOptionNumber = InteractionDataOptionBase< - ApplicationCommandOptionType.Number, - number ->; +export interface ApplicationCommandInteractionDataOptionNumber + extends InteractionDataOptionBase { + focused?: boolean; +} export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOptionBase< ApplicationCommandOptionType.Boolean, diff --git a/payloads/v9/_interactions/autocomplete.ts b/payloads/v9/_interactions/autocomplete.ts new file mode 100644 index 00000000..66e99a08 --- /dev/null +++ b/payloads/v9/_interactions/autocomplete.ts @@ -0,0 +1,6 @@ +import type { APIApplicationCommandInteractionData, APIBaseInteraction, InteractionType } from '../index'; + +export type APIApplicationCommandAutocompleteInteraction = APIBaseInteraction< + InteractionType.ApplicationCommandAutocomplete, + APIApplicationCommandInteractionData +>; diff --git a/payloads/v9/_interactions/responses.ts b/payloads/v9/_interactions/responses.ts index 5873352c..8512f3af 100644 --- a/payloads/v9/_interactions/responses.ts +++ b/payloads/v9/_interactions/responses.ts @@ -1,5 +1,6 @@ import type { MessageFlags } from '../index'; import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9'; +import type { APIApplicationCommandOptionChoice } from './applicationCommands'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type @@ -8,6 +9,7 @@ export const enum InteractionType { Ping = 1, ApplicationCommand, MessageComponent, + ApplicationCommandAutocomplete, } /** @@ -18,12 +20,18 @@ export type APIInteractionResponse = | APIInteractionResponseChannelMessageWithSource | APIInteractionResponseDeferredChannelMessageWithSource | APIInteractionResponseDeferredMessageUpdate - | APIInteractionResponseUpdateMessage; + | APIInteractionResponseUpdateMessage + | APIApplicationCommandAutocompleteResponse; export interface APIInteractionResponsePong { type: InteractionResponseType.Pong; } +export interface APIApplicationCommandAutocompleteResponse { + type: InteractionResponseType.ApplicationCommandAutocompleteResult; + data: APICommandAutocompleteInteractionResponseCallbackData; +} + export interface APIInteractionResponseChannelMessageWithSource { type: InteractionResponseType.ChannelMessageWithSource; data: APIInteractionResponseCallbackData; @@ -67,6 +75,10 @@ export const enum InteractionResponseType { * ACK a button interaction and edit the message to which the button was attached */ UpdateMessage, + /** + * For autocomplete interactions + */ + ApplicationCommandAutocompleteResult, } /** @@ -76,3 +88,7 @@ export type APIInteractionResponseCallbackData = Omit< RESTPostAPIWebhookWithTokenJSONBody, 'username' | 'avatar_url' > & { flags?: MessageFlags }; + +export interface APICommandAutocompleteInteractionResponseCallbackData { + choices?: APIApplicationCommandOptionChoice[]; +} diff --git a/payloads/v9/interactions.ts b/payloads/v9/interactions.ts index 23d29d6a..e1ef9072 100644 --- a/payloads/v9/interactions.ts +++ b/payloads/v9/interactions.ts @@ -9,6 +9,7 @@ import type { APIApplicationCommandGuildInteraction, APIApplicationCommandInteraction, } from './_interactions/applicationCommands'; +import type { APIApplicationCommandAutocompleteInteraction } from './_interactions/autocomplete'; export * from './_interactions/base'; export * from './_interactions/messageComponents'; @@ -19,7 +20,11 @@ export * from './_interactions/applicationCommands'; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object */ -export type APIInteraction = APIPingInteraction | APIApplicationCommandInteraction | APIMessageComponentInteraction; +export type APIInteraction = + | APIPingInteraction + | APIApplicationCommandInteraction + | APIMessageComponentInteraction + | APIApplicationCommandAutocompleteInteraction; /** * https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object diff --git a/rest/v8/interactions.ts b/rest/v8/interactions.ts index fae67948..d6f2ccbb 100644 --- a/rest/v8/interactions.ts +++ b/rest/v8/interactions.ts @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit< */ export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody { type?: ApplicationCommandType.ChatInput; + /** + * Whether this application command option should be autocompleted + */ + autocomplete?: boolean; description: string; } diff --git a/rest/v9/interactions.ts b/rest/v9/interactions.ts index b9491d59..d930c794 100644 --- a/rest/v9/interactions.ts +++ b/rest/v9/interactions.ts @@ -35,6 +35,10 @@ type RESTPostAPIBaseApplicationCommandsJSONBody = Omit< */ export interface RESTPostAPIChatInputApplicationCommandsJSONBody extends RESTPostAPIBaseApplicationCommandsJSONBody { type?: ApplicationCommandType.ChatInput; + /** + * Whether this application command option should be autocompleted + */ + autocomplete?: boolean; description: string; }