You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 5, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: guide/interactions/modals.md
+80-29Lines changed: 80 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ This page is a follow-up to the [interactions (slash commands) page](/slash-comm
11
11
Unlike message components, modals aren't strictly components themselves. They're a callback structure used to respond to interactions.
12
12
13
13
::: tip
14
-
You can have a maximum of five <DocsLinkpath="ActionRowBuilder:Class" />s per modal builder, and one <DocsLinkpath="TextInputBuilder:Class" /> within an <DocsLinkpath="ActionRowBuilder:Class" />. Currently, you can only use <DocsLinkpath="TextInputBuilder:Class" />s in modal action rows builders.
14
+
You can have a maximum of five <DocsLinkpath="LabelBuilder:Class" />s per modal builder, and one <DocsLinkpath="TextInputBuilder:Class" /> or <DocsLinkpath="StringSelectMenuBuilder:Class" /> within an <DocsLinkpath="LabelBuilder:Class" />.
15
15
:::
16
16
17
17
To create a modal you construct a new <DocsLinkpath="ModalBuilder:Class" />. You can then use the setters to add the custom id and title.
The custom id is a developer-defined string of up to 100 characters. Use this field to ensure you can uniquely define all incoming interactions from your modals!
36
36
:::
37
37
38
-
The next step is to add the input fields in which users responding can enter free-text. Adding inputs is similar to adding components to messages.
38
+
The next step is to add the components to which users can respond. Adding components to modals is similar to adding components to messages.
39
39
40
-
At the end, we then call <DocsLinkpath="ChatInputCommandInteraction:Class#showModal"type="method"/> to display the modal to the user.
41
-
42
-
::: warning
43
-
If you're using typescript you'll need to specify the type of components your action row holds. This can be done by specifying the generic parameter in <DocsLinkpath="ActionRowBuilder:Class" />
44
-
45
-
```diff
46
-
- new ActionRowBuilder()
47
-
+ new ActionRowBuilder<ModalActionRowComponentBuilder>()
48
-
```
49
-
:::
40
+
At the end, we then call <DocsLinkpath="ChatInputCommandInteraction:Class#showModal"type="method" /> to display the modal to the user.
Showing a modal must be the first response to an interaction. You cannot `defer()` or `deferUpdate()` then show a modal later.
121
+
Showing a modal must be the first response to an interaction. You cannot `deferReply()` or `deferUpdate()` then show a modal later.
99
122
:::
100
123
101
124
### Input styles
@@ -106,10 +129,12 @@ Currently there are two different input styles available:
106
129
107
130
### Input properties
108
131
109
-
In addition to the `customId`, `label` and `style`, a text input can be customised in a number of ways to apply validation, prompt the user, or set default values via the <DocsLinkpath="TextInputBuilder:Class" /> methods:
132
+
In addition to the `customId` and `style`, a text input can be customised in a number of ways to apply validation, prompt the user, or set default values via the <DocsLinkpath="TextInputBuilder:Class" /> methods:
110
133
111
134
```js
112
135
constinput=newTextInputBuilder()
136
+
// sets the id (not the custom id) for this component.
137
+
.setId(33)
113
138
// set the maximum number of characters to allow
114
139
.setMaxLength(1_000)
115
140
// set the minimum number of characters required for submission
@@ -122,6 +147,31 @@ const input = new TextInputBuilder()
122
147
.setRequired(true);
123
148
```
124
149
150
+
### Select Menu properties
151
+
152
+
In addition to the `customId`, `placeholder` and `options`, a text input can be customised in a number of ways to apply validation, prompt the user the <DocsLinkpath="StringSelectMenuBuilder:Class" /> methods:
153
+
154
+
```js
155
+
constinput=newStringSelectMenuBuilder()
156
+
// sets the id (not the custom id) for this component.
157
+
.setId(33)
158
+
// maximum number of option that could be selected
159
+
.setMaxValues(10)
160
+
// minimum number of option that could be selected
161
+
.setMinValues(2)
162
+
// require a selection for this select menu
163
+
.setRequired(true);
164
+
```
165
+
To add set default values of a select menu use `setDefault(true)` in the option builder
If you're using typescript, you can use the <DocsLinkpath="ModalSubmitInteraction:Class#isFromMessage"type="method"/> typeguard, to make sure the received interaction was from a `MessageComponentInteraction`.
218
+
If you're using typescript, you can use the <DocsLinkpath="ModalSubmitInteraction:Class#isFromMessage"type="method"/> type guard, to make sure the received interaction was from a <DocsLinkpath="MessageComponentInteraction:Class"/>.
0 commit comments