feat(Interactions): add modal and text input interactions (#243)

BREAKING CHANGE: `APIBaseMessageComponent` was renamed to `APIBaseComponent`
This commit is contained in:
Suneet Tipirneni
2022-02-10 05:33:50 -05:00
committed by GitHub
parent 71c4e6aecd
commit bf0f66b60a
24 changed files with 536 additions and 44 deletions

View File

@@ -0,0 +1,28 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';
export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}
export interface ModalSubmitActionRowComponent extends Omit<APIActionRowComponent<APIModalComponent>, 'components'> {
components: ModalSubmitComponent[];
}
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;

View File

@@ -1,6 +1,7 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
@@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}
/**
@@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}
export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}
export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
@@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}
/**
@@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIActionRowComponent<APIModalComponent>[];
}

View File

@@ -3,10 +3,10 @@
*/
import type { Permissions, Snowflake } from '../../globals.ts';
import type { APIApplication } from './application.ts';
import type { APIPartialEmoji } from './emoji.ts';
import type { APIGuildMember } from './guild.ts';
import type { APIMessageInteraction } from './interactions.ts';
import type { APIApplication } from './application.ts';
import type { APIRole } from './permissions.ts';
import type { APISticker, APIStickerItem } from './sticker.ts';
import type { APIUser } from './user.ts';
@@ -406,7 +406,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
@@ -976,7 +976,7 @@ export interface APIAllowedMentions {
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIBaseMessageComponent<T extends ComponentType> {
export interface APIBaseComponent<T extends ComponentType> {
/**
* The type of the component
*/
@@ -999,22 +999,27 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
components: Exclude<T, APIActionRowComponent<T>>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseMessageComponent<ComponentType.Button> {
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseComponent<ComponentType.Button> {
/**
* The label to be displayed on the button
*/
@@ -1078,10 +1083,18 @@ export enum ButtonStyle {
Link,
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APISelectMenuComponent extends APIBaseMessageComponent<ComponentType.SelectMenu> {
export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.SelectMenu> {
/**
* A developer-defined identifier for the select menu, max 100 characters
*/
@@ -1140,7 +1153,57 @@ export interface APISelectMenuOption {
default?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;
export type APIMessageActionRowComponent = APIActionRowComponent<APIMessageComponent>;
// Modal components
export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;
export type APIModalActionRowComponent = APIActionRowComponent<APIModalComponent>;

View File

@@ -16,6 +16,7 @@ export * from './_interactions/messageComponents.ts';
export * from './_interactions/ping.ts';
export * from './_interactions/responses.ts';
export * from './_interactions/applicationCommands.ts';
export * from './_interactions/modalSubmit.ts';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

View File

@@ -0,0 +1,28 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../mod.ts';
export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}
export interface ModalSubmitActionRowComponent extends Omit<APIActionRowComponent<APIModalComponent>, 'components'> {
components: ModalSubmitComponent[];
}
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;

View File

@@ -1,6 +1,7 @@
import type { MessageFlags } from '../mod.ts';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9.ts';
import type { APIApplicationCommandOptionChoice } from './applicationCommands.ts';
import type { APIActionRowComponent, APIModalComponent } from '../channel.ts';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
@@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}
/**
@@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}
export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}
export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
@@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}
/**
@@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIActionRowComponent<APIModalComponent>[];
}

View File

@@ -3,10 +3,10 @@
*/
import type { Permissions, Snowflake } from '../../globals.ts';
import type { APIApplication } from './application.ts';
import type { APIPartialEmoji } from './emoji.ts';
import type { APIGuildMember } from './guild.ts';
import type { APIMessageInteraction } from './interactions.ts';
import type { APIApplication } from './application.ts';
import type { APIRole } from './permissions.ts';
import type { APISticker, APIStickerItem } from './sticker.ts';
import type { APIUser } from './user.ts';
@@ -483,7 +483,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
@@ -1145,7 +1145,7 @@ export interface APIAllowedMentions {
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIBaseMessageComponent<T extends ComponentType> {
export interface APIBaseComponent<T extends ComponentType> {
/**
* The type of the component
*/
@@ -1168,22 +1168,27 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
components: Exclude<T, APIActionRowComponent<T>>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseMessageComponent<ComponentType.Button> {
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseComponent<ComponentType.Button> {
/**
* The label to be displayed on the button
*/
@@ -1247,10 +1252,18 @@ export enum ButtonStyle {
Link,
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APISelectMenuComponent extends APIBaseMessageComponent<ComponentType.SelectMenu> {
export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.SelectMenu> {
/**
* A developer-defined identifier for the select menu, max 100 characters
*/
@@ -1309,7 +1322,57 @@ export interface APISelectMenuOption {
default?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;
export type APIMessageActionRowComponent = APIActionRowComponent<APIMessageComponent>;
// Modal components
export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;
export type APIModalActionRowComponent = APIActionRowComponent<APIModalComponent>;

View File

@@ -16,6 +16,7 @@ export * from './_interactions/messageComponents.ts';
export * from './_interactions/ping.ts';
export * from './_interactions/responses.ts';
export * from './_interactions/applicationCommands.ts';
export * from './_interactions/modalSubmit.ts';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

View File

@@ -1,6 +1,7 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type {
APIActionRowComponent,
APIMessageComponent,
APIAllowedMentions,
APIAttachment,
APIChannel,
@@ -213,7 +214,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
@@ -347,7 +348,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;
/**

View File

@@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v8/mod.ts';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals.ts';
@@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals.ts';
import type {
APIMessageComponent,
APIActionRowComponent,
APIAllowedMentions,
APIAttachment,
@@ -246,7 +247,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
@@ -380,7 +381,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;
/**

View File

@@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v9/mod.ts';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals.ts';
@@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/

View File

@@ -0,0 +1,28 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';
export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}
export interface ModalSubmitActionRowComponent extends Omit<APIActionRowComponent<APIModalComponent>, 'components'> {
components: ModalSubmitComponent[];
}
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;

View File

@@ -1,6 +1,7 @@
import type { MessageFlags } from '../index';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v8';
import type { APIApplicationCommandOptionChoice } from './applicationCommands';
import type { APIActionRowComponent, APIModalComponent } from '../channel';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
@@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}
/**
@@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}
export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}
export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
@@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}
/**
@@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIActionRowComponent<APIModalComponent>[];
}

View File

@@ -3,10 +3,10 @@
*/
import type { Permissions, Snowflake } from '../../globals';
import type { APIApplication } from './application';
import type { APIPartialEmoji } from './emoji';
import type { APIGuildMember } from './guild';
import type { APIMessageInteraction } from './interactions';
import type { APIApplication } from './application';
import type { APIRole } from './permissions';
import type { APISticker, APIStickerItem } from './sticker';
import type { APIUser } from './user';
@@ -406,7 +406,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
@@ -976,7 +976,7 @@ export interface APIAllowedMentions {
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIBaseMessageComponent<T extends ComponentType> {
export interface APIBaseComponent<T extends ComponentType> {
/**
* The type of the component
*/
@@ -999,22 +999,27 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
components: Exclude<T, APIActionRowComponent<T>>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseMessageComponent<ComponentType.Button> {
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseComponent<ComponentType.Button> {
/**
* The label to be displayed on the button
*/
@@ -1078,10 +1083,18 @@ export enum ButtonStyle {
Link,
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APISelectMenuComponent extends APIBaseMessageComponent<ComponentType.SelectMenu> {
export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.SelectMenu> {
/**
* A developer-defined identifier for the select menu, max 100 characters
*/
@@ -1140,7 +1153,57 @@ export interface APISelectMenuOption {
default?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;
export type APIMessageActionRowComponent = APIActionRowComponent<APIMessageComponent>;
// Modal components
export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;
export type APIModalActionRowComponent = APIActionRowComponent<APIModalComponent>;

View File

@@ -16,6 +16,7 @@ export * from './_interactions/messageComponents';
export * from './_interactions/ping';
export * from './_interactions/responses';
export * from './_interactions/applicationCommands';
export * from './_interactions/modalSubmit';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

View File

@@ -0,0 +1,28 @@
import type { APIActionRowComponent, APIModalComponent } from '../channel';
import type { APIBaseInteraction, InteractionType, ComponentType } from '../index';
export interface ModalSubmitComponent {
type: ComponentType;
custom_id: string;
value: string;
}
export interface ModalSubmitActionRowComponent extends Omit<APIActionRowComponent<APIModalComponent>, 'components'> {
components: ModalSubmitComponent[];
}
export interface APIModalSubmission {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* A list of child components
*/
components?: ModalSubmitActionRowComponent[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
*/
export type APIModalSubmitInteraction = APIBaseInteraction<InteractionType.ModalSubmit, APIModalSubmission>;

View File

@@ -1,6 +1,7 @@
import type { MessageFlags } from '../index';
import type { RESTPostAPIWebhookWithTokenJSONBody } from '../../../v9';
import type { APIApplicationCommandOptionChoice } from './applicationCommands';
import type { APIActionRowComponent, APIModalComponent } from '../channel';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
@@ -10,6 +11,7 @@ export enum InteractionType {
ApplicationCommand,
MessageComponent,
ApplicationCommandAutocomplete,
ModalSubmit,
}
/**
@@ -32,6 +34,11 @@ export interface APIApplicationCommandAutocompleteResponse {
data: APICommandAutocompleteInteractionResponseCallbackData;
}
export interface APIModalInteractionResponse {
type: InteractionResponseType.Modal;
data: APIModalInteractionResponseCallbackData;
}
export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
@@ -79,6 +86,10 @@ export enum InteractionResponseType {
* For autocomplete interactions
*/
ApplicationCommandAutocompleteResult,
/**
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
}
/**
@@ -92,3 +103,21 @@ export type APIInteractionResponseCallbackData = Omit<
export interface APICommandAutocompleteInteractionResponseCallbackData {
choices?: APIApplicationCommandOptionChoice[];
}
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-response-object-modal
*/
export interface APIModalInteractionResponseCallbackData {
/**
* A developer-defined identifier for the component, max 100 characters
*/
custom_id: string;
/**
* The title of the popup modal
*/
title: string;
/**
* Between 1 and 5 (inclusive) components that make up the modal
*/
components: APIActionRowComponent<APIModalComponent>[];
}

View File

@@ -3,10 +3,10 @@
*/
import type { Permissions, Snowflake } from '../../globals';
import type { APIApplication } from './application';
import type { APIPartialEmoji } from './emoji';
import type { APIGuildMember } from './guild';
import type { APIMessageInteraction } from './interactions';
import type { APIApplication } from './application';
import type { APIRole } from './permissions';
import type { APISticker, APIStickerItem } from './sticker';
import type { APIUser } from './user';
@@ -483,7 +483,7 @@ export interface APIMessage {
/**
* Sent if the message contains components like buttons, action rows, or other interactive components
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Sent if the message contains stickers
*
@@ -1145,7 +1145,7 @@ export interface APIAllowedMentions {
/**
* https://discord.com/developers/docs/interactions/message-components#component-object
*/
export interface APIBaseMessageComponent<T extends ComponentType> {
export interface APIBaseComponent<T extends ComponentType> {
/**
* The type of the component
*/
@@ -1168,22 +1168,27 @@ export enum ComponentType {
* Select Menu component
*/
SelectMenu,
/**
* Text Input component
*/
TextInput,
}
/**
* https://discord.com/developers/docs/interactions/message-components#action-rows
*/
export interface APIActionRowComponent extends APIBaseMessageComponent<ComponentType.ActionRow> {
export interface APIActionRowComponent<T extends APIActionRowComponentTypes>
extends APIBaseComponent<ComponentType.ActionRow> {
/**
* The components in the ActionRow
*/
components: Exclude<APIMessageComponent, APIActionRowComponent>[];
components: Exclude<T, APIActionRowComponent<T>>[];
}
/**
* https://discord.com/developers/docs/interactions/message-components#buttons
*/
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseMessageComponent<ComponentType.Button> {
interface APIButtonComponentBase<Style extends ButtonStyle> extends APIBaseComponent<ComponentType.Button> {
/**
* The label to be displayed on the button
*/
@@ -1247,10 +1252,18 @@ export enum ButtonStyle {
Link,
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-styles
*/
export enum TextInputStyle {
Short = 1,
Paragraph,
}
/**
* https://discord.com/developers/docs/interactions/message-components#select-menus
*/
export interface APISelectMenuComponent extends APIBaseMessageComponent<ComponentType.SelectMenu> {
export interface APISelectMenuComponent extends APIBaseComponent<ComponentType.SelectMenu> {
/**
* A developer-defined identifier for the select menu, max 100 characters
*/
@@ -1309,7 +1322,57 @@ export interface APISelectMenuOption {
default?: boolean;
}
/**
* https://discord.com/developers/docs/interactions/message-components#text-inputs-text-input-structure
*/
export interface APITextInputComponent extends APIBaseComponent<ComponentType.TextInput> {
/**
* One of text input styles
*/
style: TextInputStyle;
/**
* The custom id for the text input
*/
custom_id: string;
/**
* Text that appears on top of the text input field, max 80 characters
*/
label: string;
/**
* Placeholder for the text input
*/
placeholder?: string;
/**
* The pre-filled text in the text input
*/
value?: string;
/**
* Minimal length of text input
*/
min_length?: number;
/**
* Maximal length of text input
*/
max_length?: number;
/**
* Whether or not this text input is required or not
*/
required?: boolean;
}
export type APIActionRowComponentTypes = APIMessageComponent | APIModalComponent;
/**
* https://discord.com/developers/docs/interactions/message-components#message-components
*/
export type APIMessageComponent = APIActionRowComponent | APIButtonComponent | APISelectMenuComponent;
export type APIMessageComponent =
| APIActionRowComponent<APIMessageComponent>
| APIButtonComponent
| APISelectMenuComponent;
export type APIMessageActionRowComponent = APIActionRowComponent<APIMessageComponent>;
// Modal components
export type APIModalComponent = APIActionRowComponent<APIModalComponent> | APITextInputComponent;
export type APIModalActionRowComponent = APIActionRowComponent<APIModalComponent>;

View File

@@ -16,6 +16,7 @@ export * from './_interactions/messageComponents';
export * from './_interactions/ping';
export * from './_interactions/responses';
export * from './_interactions/applicationCommands';
export * from './_interactions/modalSubmit';
/**
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object

View File

@@ -1,6 +1,7 @@
import type { Permissions, Snowflake } from '../../globals';
import type {
APIActionRowComponent,
APIMessageComponent,
APIAllowedMentions,
APIAttachment,
APIChannel,
@@ -213,7 +214,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
@@ -347,7 +348,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;
/**

View File

@@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v8/index';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals';
@@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/

View File

@@ -1,5 +1,6 @@
import type { Permissions, Snowflake } from '../../globals';
import type {
APIMessageComponent,
APIActionRowComponent,
APIAllowedMentions,
APIAttachment,
@@ -246,7 +247,7 @@ export type RESTPostAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefinedP
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* IDs of up to 3 stickers in the server to send in the message
*
@@ -380,7 +381,7 @@ export type RESTPatchAPIChannelMessageJSONBody = AddUndefinedToPossiblyUndefined
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[] | null;
components?: APIActionRowComponent<APIMessageComponent>[] | null;
}>;
/**

View File

@@ -7,6 +7,7 @@ import type {
APIWebhook,
APIAttachment,
MessageFlags,
APIMessageComponent,
} from '../../payloads/v9/index';
import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, Nullable } from '../../utils/internals';
@@ -135,7 +136,7 @@ export type RESTPostAPIWebhookWithTokenJSONBody = AddUndefinedToPossiblyUndefine
*
* See https://discord.com/developers/docs/interactions/message-components#component-object
*/
components?: APIActionRowComponent[];
components?: APIActionRowComponent<APIMessageComponent>[];
/**
* Attachment objects with filename and description
*/