Skip to main content
modal() declares a form, from any file of src/; the name of its export is its id. It takes one object, ModalConfig, and types fields in run from it.
src/components/feedback.ts
How to write a form, open it and read what was filled in is in the guide. This page lists what exists. The place (where, PlaceOf…) is on the button() page.
Declares a form. Export the result from any file of src/: the name of the export is what tells the form apart, so you never write an id.

ModalDeclaration

What modal() returns: a declaration the framework finds in the exports of a file. Import it where someone uses a command or a component, and open it: interaction.showModal(report({ userId })), or interaction.showModal(feedback) for a form without data.
unknown
What the file gave to modal(), not checked yet.

ModalInstanceOptions

What a form is opened with: its data, and what some fields hold.
ModalPrefill<Fields>
What some fields hold when the form opens.

ModalPrefill

What a form can hold when it opens: a value for some of its fields. A string for a text, a list of values for a select or checkboxes, one value for a radio, a boolean for a checkbox. The other kinds of fields can’t be filled in advance.

ModalConfig

What a modal file gives to modal().
DynamicText
required
The title of the form (45 characters at most): written as is, or a function of t and the data, run when the form opens. See DynamicText.
ModalFields
required
The fields, by name (1 to 5). run receives them under the same names.
(context: ModalContext<Fields, Data, Where>) => unknown
required
What to do when someone sends the form.
DataShape
What the form carries from the code that opens it to the code that runs when it is sent: a name and a kind for each value. Given when the form is opened, received typed in run.
ComponentWhere
Where the form can be sent from: 'guild' (servers, the default), 'dm' (private messages with the bot) or 'both'. What run receives follows it.
boolean
Make the answers of the form only visible to who sent it. When a component of a message only the person sees opened it, they already are.
Discord documentation

Fields

ModalFields

The fields of a form, by name (5 at most). A name is how your code reads the field (fields.reason): letters, digits and _.

ModalField

One field of a form. Every field but a note has:
DynamicText
required
The name of the field, above it (45 characters at most): written as is, or a function of t and the data, run when the form opens.
DynamicText
A help text under the label (100 characters at most): a text, or a function of t and the data.
Discord documentation

TextField

A text the person types.
'text'
required
The kind of field: a text.
'short' | 'paragraph'
One line ('short', the default) or several ('paragraph').
DynamicText
The text shown while the field is empty (100 characters at most): a text, or a function of t and the data.
boolean
Whether the person must fill it in. true by default.
number
The shortest text accepted, in characters (0 to 4000).
number
The longest text accepted, in characters (1 to 4000).
string
What the field holds when the form opens (4000 characters at most).
Discord documentation

SelectField

A menu of texts you declare.
'select'
required
The kind of field: a menu of texts.
SelectOptions
required
The options (25 at most), written like the options of a select menu.
DynamicText
The text shown when nothing is picked (150 characters at most): a text, or a function of t and the data.
number
How many options must be picked at least (0 to 25). 1 by default.
number
How many options can be picked at most (1 to 25). 1 by default.
boolean
Whether something must be picked. true by default.

EntityField

A menu of users, roles, users and roles, or channels of the server.
'user' | 'role' | 'mentionable' | 'channel'
required
The kind of field: what Discord lists.
DynamicText
The text shown when nothing is picked (150 characters at most): a text, or a function of t and the data.
number
How many things must be picked at least (0 to 25). 1 by default.
number
How many things can be picked at most (1 to 25). 1 by default.
boolean
Whether something must be picked. true by default.
readonly ChannelType[]
For a menu of channels: the kinds of channels listed. All by default.

FilesField

Files the person uploads.
'files'
required
The kind of field: files to upload.
number
How many files must be uploaded at least (0 to 10). 1 by default.
number
How many files can be uploaded at most (1 to 10). 1 by default.
boolean
Whether files must be uploaded. true by default.
readonly string[]
The kinds of files accepted: 'image', 'video', 'audio', or extensions like '.pdf' (10 at most).
Discord documentation

RadioField

One choice among a few, shown as radio buttons.
'radio'
required
The kind of field: one choice among 2 to 10.
SelectOptions
required
The choices (2 to 10), written like the options of a select menu.
boolean
Whether a choice must be made. true by default.
Discord documentation

CheckboxesField

Several choices among a few, shown as checkboxes.
'checkboxes'
required
The kind of field: several choices among 1 to 10.
SelectOptions
required
The choices (1 to 10), written like the options of a select menu.
number
How many must be checked at least (0 to 10). 1 by default.
number
How many can be checked at most (1 to 10). All by default.
boolean
Whether something must be checked. true by default.
Discord documentation

CheckboxField

One checkbox: yes or no.
'checkbox'
required
The kind of field: one checkbox.
boolean
Whether it is checked when the form opens.
Discord documentation

NoteField

A text shown in the form, which nobody fills in.
'note'
required
The kind of field: a text to read.
DynamicText
required
The text, with Markdown: written as is, or a function of t and the data.
Discord documentation

What run receives

ModalContext

What run receives when the form is sent: the place as PlaceOf gives it with a ModalInteraction, and:
User
required
Who sent the form.
FieldValuesOf<Fields>
required
What the person filled in.
DataValuesOf<Data>
required
What the form carries, as declared in data.
Message | null
required
The message whose button or menu opened the form; null when a command did.

FieldValuesOf

What the person filled in, typed field by field. Notes are not there.

FieldValue

What run receives for a field, from its declaration: Discord documentation