feat(Interactions): components and component interactions (#132)

Co-authored-by: nearlySplat <splatterxl@outlook.ie>
Co-authored-by: Advaith <advaithj1@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
monbrey
2021-06-20 04:18:10 +10:00
committed by GitHub
parent 16eae7eafe
commit 036bb035c9
12 changed files with 792 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ import type {
APIGuildIntegration,
APIGuildMember,
APIMessage,
APIMessageComponentInteraction,
APIRole,
APIUnavailableGuild,
APIUser,
@@ -889,7 +890,7 @@ export type GatewayInteractionCreateDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway#interaction-create
*/
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction;
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction | APIMessageComponentInteraction;
/**
* https://discord.com/developers/docs/topics/gateway#invite-create

View File

@@ -13,6 +13,7 @@ import type {
APIGuildIntegration,
APIGuildMember,
APIMessage,
APIMessageComponentInteraction,
APIRole,
APIThreadMember,
APIUnavailableGuild,
@@ -902,7 +903,7 @@ export type GatewayInteractionCreateDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway#interaction-create
*/
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction;
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction | APIMessageComponentInteraction;
/**
* https://discord.com/developers/docs/topics/gateway#invite-create

View File

@@ -342,6 +342,10 @@ export interface APIMessage {
* Sent if the message is a response to an Interaction
*/
interaction?: APIMessageInteraction;
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
}
/**
@@ -930,3 +934,148 @@ export interface APIAllowedMentions {
*/
replied_user?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components
*/
export interface APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-types
*/
export enum ComponentType {
/**
* ActionRow component
*/
ActionRow = 1,
/**
* Button component
*/
Button,
/**
* Select Menu component
*/
SelectMenu,
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIActionRowComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.ActionRow;
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-object
*/
export interface APIButtonComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.Button;
/**
* The label to be displayed on the button
*/
label?: string;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id?: string;
/**
* The style of the button
*/
style: ButtonStyle;
/**
* The emoji to display to the left of the text
*/
emoji?: APIPartialEmoji;
/**
* The URL to direct users to when clicked for Link buttons
*/
url?: string;
/**
* The status of the button
*/
disabled?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectMenuComponent {
/**
* The type of the component
*/
type: ComponentType.SelectMenu;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id: string;
/**
* Custom placeholder text if nothing is selected
*/
placeholder?: string;
/**
* The minimum number of items that must be chosen
*/
min_values?: number;
/**
* The maximum number of items that can be chosen
*/
max_values?: number;
/**
* Choices to display in the select menu
*/
options: APISelectOption[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectOption {
/**
* The user-facing name of the option (max 25 chars)
*/
label: string;
/**
* The dev-defined value of the option (max 100 chars)
*/
value: string;
/**
* An additional description of the option (max 50 chars)
*/
description?: string;
/**
* The emoji to display to the left of the option
*/
emoji?: APIPartialEmoji;
/**
* Whether this option should be already-selected by default
*/
default: boolean;
}
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-styles
*/
export enum ButtonStyle {
Primary = 1,
Secondary,
Success,
Danger,
Link,
}

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../rest/v8/mod.ts';
import { APIMessage, ComponentType } from './channel.ts';
import type { APIGuildMember, APIPartialChannel, APIRole, APIUser, MessageFlags } from './mod.ts';
/**
@@ -118,7 +119,7 @@ export interface APIBaseInteraction {
/**
* The command data payload
*/
data?: APIApplicationCommandInteractionData;
data?: APIApplicationCommandInteractionData | APIMessageComponentInteractionData;
/**
* The channel it was sent from
*/
@@ -169,10 +170,20 @@ export interface APIDMInteraction extends APIBaseInteraction {
channel_id: Snowflake;
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-interaction
*/
export interface APIMessageComponentInteraction extends APIBaseInteraction {
/**
* Message object to which the button was attached
*/
message: APIMessage;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction
*/
export type APIInteraction = APIGuildInteraction | APIDMInteraction;
export type APIInteraction = APIGuildInteraction | APIDMInteraction | APIMessageComponentInteraction;
/**
* Like APIGuildInteraction, only with the `data` property always present
@@ -203,6 +214,7 @@ export type APIApplicationCommandInteraction =
export enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
}
/**
@@ -346,13 +358,28 @@ export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOpti
boolean
>;
export interface APIMessageButtonInteractionData {
custom_id: string;
component_type: ComponentType.Button;
}
export interface APIMessageSelectMenuInteractionData {
custom_id: string;
component_type: ComponentType.SelectMenu;
values: string[];
}
export type APIMessageComponentInteractionData = APIMessageButtonInteractionData | APIMessageSelectMenuInteractionData;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response
*/
export type APIInteractionResponse =
| APIInteractionResponsePong
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource;
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
@@ -368,6 +395,15 @@ export interface APIInteractionResponseDeferredChannelMessageWithSource {
data?: Pick<APIInteractionApplicationCommandCallbackData, 'flags'>;
}
export interface APIInteractionResponseDeferredMessageUpdate {
type: InteractionResponseType.DeferredMessageUpdate;
}
export interface APIInteractionResponseUpdateMessage {
type: InteractionResponseType.UpdateMessage;
data?: APIInteractionApplicationCommandCallbackData;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype
*/
@@ -384,6 +420,14 @@ export enum InteractionResponseType {
* ACK an interaction and edit to a response later, the user sees a loading state
*/
DeferredChannelMessageWithSource,
/**
* ACK a button interaction and update it to a loading state
*/
DeferredMessageUpdate,
/**
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
}
/**

View File

@@ -378,6 +378,10 @@ export interface APIMessage {
* Sent if the message is a response to an Interaction
*/
interaction?: APIMessageInteraction;
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
/**
* Sent if a thread was started from this message
*/
@@ -1046,3 +1050,148 @@ export interface APIAllowedMentions {
*/
replied_user?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components
*/
export interface APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-types
*/
export enum ComponentType {
/**
* ActionRow component
*/
ActionRow = 1,
/**
* Button component
*/
Button,
/**
* Select Menu component
*/
SelectMenu,
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIActionRowComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.ActionRow;
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-object
*/
export interface APIButtonComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.Button;
/**
* The label to be displayed on the button
*/
label?: string;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id?: string;
/**
* The style of the button
*/
style: ButtonStyle;
/**
* The emoji to display to the left of the text
*/
emoji?: APIPartialEmoji;
/**
* The URL to direct users to when clicked for Link buttons
*/
url?: string;
/**
* The status of the button
*/
disabled?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectMenuComponent {
/**
* The type of the component
*/
type: ComponentType.SelectMenu;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id: string;
/**
* Custom placeholder text if nothing is selected
*/
placeholder?: string;
/**
* The minimum number of items that must be chosen
*/
min_values?: number;
/**
* The maximum number of items that can be chosen
*/
max_values?: number;
/**
* Choices to display in the select menu
*/
options: APISelectOption[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectOption {
/**
* The user-facing name of the option (max 25 chars)
*/
label: string;
/**
* The dev-defined value of the option (max 100 chars)
*/
value: string;
/**
* An additional description of the option (max 50 chars)
*/
description?: string;
/**
* The emoji to display to the left of the option
*/
emoji?: APIPartialEmoji;
/**
* Whether this option should be already-selected by default
*/
default: boolean;
}
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-styles
*/
export enum ButtonStyle {
Primary = 1,
Secondary,
Success,
Danger,
Link,
}

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../rest/v9/mod.ts';
import { APIMessage, ComponentType } from './channel.ts';
import type { APIGuildMember, APIPartialChannel, APIRole, APIUser, MessageFlags } from './mod.ts';
/**
@@ -118,7 +119,7 @@ export interface APIBaseInteraction {
/**
* The command data payload
*/
data?: APIApplicationCommandInteractionData;
data?: APIApplicationCommandInteractionData | APIMessageComponentInteractionData;
/**
* The channel it was sent from
*/
@@ -169,10 +170,20 @@ export interface APIDMInteraction extends APIBaseInteraction {
channel_id: Snowflake;
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-interaction
*/
export interface APIMessageComponentInteraction extends APIBaseInteraction {
/**
* Message object to which the button was attached
*/
message: APIMessage;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction
*/
export type APIInteraction = APIGuildInteraction | APIDMInteraction;
export type APIInteraction = APIGuildInteraction | APIDMInteraction | APIMessageComponentInteraction;
/**
* Like APIGuildInteraction, only with the `data` property always present
@@ -203,6 +214,7 @@ export type APIApplicationCommandInteraction =
export enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
}
/**
@@ -346,13 +358,28 @@ export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOpti
boolean
>;
export interface APIMessageButtonInteractionData {
custom_id: string;
component_type: ComponentType.Button;
}
export interface APIMessageSelectMenuInteractionData {
custom_id: string;
component_type: ComponentType.SelectMenu;
values: string[];
}
export type APIMessageComponentInteractionData = APIMessageButtonInteractionData | APIMessageSelectMenuInteractionData;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response
*/
export type APIInteractionResponse =
| APIInteractionResponsePong
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource;
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
@@ -368,6 +395,15 @@ export interface APIInteractionResponseDeferredChannelMessageWithSource {
data?: Pick<APIInteractionApplicationCommandCallbackData, 'flags'>;
}
export interface APIInteractionResponseDeferredMessageUpdate {
type: InteractionResponseType.DeferredMessageUpdate;
}
export interface APIInteractionResponseUpdateMessage {
type: InteractionResponseType.UpdateMessage;
data?: APIInteractionApplicationCommandCallbackData;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype
*/
@@ -384,6 +420,14 @@ export enum InteractionResponseType {
* ACK an interaction and edit to a response later, the user sees a loading state
*/
DeferredChannelMessageWithSource,
/**
* ACK a button interaction and update it to a loading state
*/
DeferredMessageUpdate,
/**
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
}
/**

View File

@@ -13,6 +13,7 @@ import type {
APIGuildIntegration,
APIGuildMember,
APIMessage,
APIMessageComponentInteraction,
APIRole,
APIUnavailableGuild,
APIUser,
@@ -889,7 +890,7 @@ export type GatewayInteractionCreateDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway#interaction-create
*/
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction;
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction | APIMessageComponentInteraction;
/**
* https://discord.com/developers/docs/topics/gateway#invite-create

View File

@@ -13,6 +13,7 @@ import type {
APIGuildIntegration,
APIGuildMember,
APIMessage,
APIMessageComponentInteraction,
APIRole,
APIThreadMember,
APIUnavailableGuild,
@@ -902,7 +903,7 @@ export type GatewayInteractionCreateDispatch = DataPayload<
/**
* https://discord.com/developers/docs/topics/gateway#interaction-create
*/
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction;
export type GatewayInteractionCreateDispatchData = APIApplicationCommandInteraction | APIMessageComponentInteraction;
/**
* https://discord.com/developers/docs/topics/gateway#invite-create

View File

@@ -342,6 +342,10 @@ export interface APIMessage {
* Sent if the message is a response to an Interaction
*/
interaction?: APIMessageInteraction;
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
}
/**
@@ -930,3 +934,148 @@ export interface APIAllowedMentions {
*/
replied_user?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components
*/
export interface APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-types
*/
export const enum ComponentType {
/**
* ActionRow component
*/
ActionRow = 1,
/**
* Button component
*/
Button,
/**
* Select Menu component
*/
SelectMenu,
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIActionRowComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.ActionRow;
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-object
*/
export interface APIButtonComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.Button;
/**
* The label to be displayed on the button
*/
label?: string;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id?: string;
/**
* The style of the button
*/
style: ButtonStyle;
/**
* The emoji to display to the left of the text
*/
emoji?: APIPartialEmoji;
/**
* The URL to direct users to when clicked for Link buttons
*/
url?: string;
/**
* The status of the button
*/
disabled?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectMenuComponent {
/**
* The type of the component
*/
type: ComponentType.SelectMenu;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id: string;
/**
* Custom placeholder text if nothing is selected
*/
placeholder?: string;
/**
* The minimum number of items that must be chosen
*/
min_values?: number;
/**
* The maximum number of items that can be chosen
*/
max_values?: number;
/**
* Choices to display in the select menu
*/
options: APISelectOption[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectOption {
/**
* The user-facing name of the option (max 25 chars)
*/
label: string;
/**
* The dev-defined value of the option (max 100 chars)
*/
value: string;
/**
* An additional description of the option (max 50 chars)
*/
description?: string;
/**
* The emoji to display to the left of the option
*/
emoji?: APIPartialEmoji;
/**
* Whether this option should be already-selected by default
*/
default: boolean;
}
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-styles
*/
export const enum ButtonStyle {
Primary = 1,
Secondary,
Success,
Danger,
Link,
}

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../rest/v8/index';
import { APIMessage, ComponentType } from './channel';
import type { APIGuildMember, APIPartialChannel, APIRole, APIUser, MessageFlags } from './index';
/**
@@ -118,7 +119,7 @@ export interface APIBaseInteraction {
/**
* The command data payload
*/
data?: APIApplicationCommandInteractionData;
data?: APIApplicationCommandInteractionData | APIMessageComponentInteractionData;
/**
* The channel it was sent from
*/
@@ -169,10 +170,20 @@ export interface APIDMInteraction extends APIBaseInteraction {
channel_id: Snowflake;
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-interaction
*/
export interface APIMessageComponentInteraction extends APIBaseInteraction {
/**
* Message object to which the button was attached
*/
message: APIMessage;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction
*/
export type APIInteraction = APIGuildInteraction | APIDMInteraction;
export type APIInteraction = APIGuildInteraction | APIDMInteraction | APIMessageComponentInteraction;
/**
* Like APIGuildInteraction, only with the `data` property always present
@@ -203,6 +214,7 @@ export type APIApplicationCommandInteraction =
export const enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
}
/**
@@ -346,13 +358,28 @@ export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOpti
boolean
>;
export interface APIMessageButtonInteractionData {
custom_id: string;
component_type: ComponentType.Button;
}
export interface APIMessageSelectMenuInteractionData {
custom_id: string;
component_type: ComponentType.SelectMenu;
values: string[];
}
export type APIMessageComponentInteractionData = APIMessageButtonInteractionData | APIMessageSelectMenuInteractionData;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response
*/
export type APIInteractionResponse =
| APIInteractionResponsePong
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource;
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
@@ -368,6 +395,15 @@ export interface APIInteractionResponseDeferredChannelMessageWithSource {
data?: Pick<APIInteractionApplicationCommandCallbackData, 'flags'>;
}
export interface APIInteractionResponseDeferredMessageUpdate {
type: InteractionResponseType.DeferredMessageUpdate;
}
export interface APIInteractionResponseUpdateMessage {
type: InteractionResponseType.UpdateMessage;
data?: APIInteractionApplicationCommandCallbackData;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype
*/
@@ -384,6 +420,14 @@ export const enum InteractionResponseType {
* ACK an interaction and edit to a response later, the user sees a loading state
*/
DeferredChannelMessageWithSource,
/**
* ACK a button interaction and update it to a loading state
*/
DeferredMessageUpdate,
/**
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
}
/**

View File

@@ -378,6 +378,10 @@ export interface APIMessage {
* Sent if the message is a response to an Interaction
*/
interaction?: APIMessageInteraction;
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
/**
* Sent if a thread was started from this message
*/
@@ -1046,3 +1050,148 @@ export interface APIAllowedMentions {
*/
replied_user?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components
*/
export interface APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-types
*/
export const enum ComponentType {
/**
* ActionRow component
*/
ActionRow = 1,
/**
* Button component
*/
Button,
/**
* Select Menu component
*/
SelectMenu,
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIActionRowComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.ActionRow;
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-object
*/
export interface APIButtonComponent extends APIBaseComponent {
/**
* The type of the component
*/
type: ComponentType.Button;
/**
* The label to be displayed on the button
*/
label?: string;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id?: string;
/**
* The style of the button
*/
style: ButtonStyle;
/**
* The emoji to display to the left of the text
*/
emoji?: APIPartialEmoji;
/**
* The URL to direct users to when clicked for Link buttons
*/
url?: string;
/**
* The status of the button
*/
disabled?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectMenuComponent {
/**
* The type of the component
*/
type: ComponentType.SelectMenu;
/**
* The custom_id to be sent in the interaction when clicked
*/
custom_id: string;
/**
* Custom placeholder text if nothing is selected
*/
placeholder?: string;
/**
* The minimum number of items that must be chosen
*/
min_values?: number;
/**
* The maximum number of items that can be chosen
*/
max_values?: number;
/**
* Choices to display in the select menu
*/
options: APISelectOption[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APISelectOption {
/**
* The user-facing name of the option (max 25 chars)
*/
label: string;
/**
* The dev-defined value of the option (max 100 chars)
*/
value: string;
/**
* An additional description of the option (max 50 chars)
*/
description?: string;
/**
* The emoji to display to the left of the option
*/
emoji?: APIPartialEmoji;
/**
* Whether this option should be already-selected by default
*/
default: boolean;
}
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-styles
*/
export const enum ButtonStyle {
Primary = 1,
Secondary,
Success,
Danger,
Link,
}

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../rest/v9/index';
import { APIMessage, ComponentType } from './channel';
import type { APIGuildMember, APIPartialChannel, APIRole, APIUser, MessageFlags } from './index';
/**
@@ -118,7 +119,7 @@ export interface APIBaseInteraction {
/**
* The command data payload
*/
data?: APIApplicationCommandInteractionData;
data?: APIApplicationCommandInteractionData | APIMessageComponentInteractionData;
/**
* The channel it was sent from
*/
@@ -169,10 +170,20 @@ export interface APIDMInteraction extends APIBaseInteraction {
channel_id: Snowflake;
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons-button-interaction
*/
export interface APIMessageComponentInteraction extends APIBaseInteraction {
/**
* Message object to which the button was attached
*/
message: APIMessage;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction
*/
export type APIInteraction = APIGuildInteraction | APIDMInteraction;
export type APIInteraction = APIGuildInteraction | APIDMInteraction | APIMessageComponentInteraction;
/**
* Like APIGuildInteraction, only with the `data` property always present
@@ -203,6 +214,7 @@ export type APIApplicationCommandInteraction =
export const enum InteractionType {
Ping = 1,
ApplicationCommand,
MessageComponent,
}
/**
@@ -346,13 +358,28 @@ export type ApplicationCommandInteractionDataOptionBoolean = InteractionDataOpti
boolean
>;
export interface APIMessageButtonInteractionData {
custom_id: string;
component_type: ComponentType.Button;
}
export interface APIMessageSelectMenuInteractionData {
custom_id: string;
component_type: ComponentType.SelectMenu;
values: string[];
}
export type APIMessageComponentInteractionData = APIMessageButtonInteractionData | APIMessageSelectMenuInteractionData;
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response
*/
export type APIInteractionResponse =
| APIInteractionResponsePong
| APIInteractionResponseChannelMessageWithSource
| APIInteractionResponseDeferredChannelMessageWithSource;
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage;
export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
@@ -368,6 +395,15 @@ export interface APIInteractionResponseDeferredChannelMessageWithSource {
data?: Pick<APIInteractionApplicationCommandCallbackData, 'flags'>;
}
export interface APIInteractionResponseDeferredMessageUpdate {
type: InteractionResponseType.DeferredMessageUpdate;
}
export interface APIInteractionResponseUpdateMessage {
type: InteractionResponseType.UpdateMessage;
data?: APIInteractionApplicationCommandCallbackData;
}
/**
* https://discord.com/developers/docs/interactions/slash-commands#interaction-response-interactionresponsetype
*/
@@ -384,6 +420,14 @@ export const enum InteractionResponseType {
* ACK an interaction and edit to a response later, the user sees a loading state
*/
DeferredChannelMessageWithSource,
/**
* ACK a button interaction and update it to a loading state
*/
DeferredMessageUpdate,
/**
* ACK a button interaction and edit the message to which the button was attached
*/
UpdateMessage,
}
/**