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.modal()
src/: the name of the export is what tells the form apart, so you never write an id.
ModalDeclaration
Whatmodal() 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.
ModalInstanceOptions
What a form is opened with: its data, and what some fields hold.ModalPrefill
What a form can hold when it opens: a value for some of its fields. Astring 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 tomodal().
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.What to do when someone sends the form.
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.Where the form can be sent from:
'guild' (servers, the default), 'dm' (private messages with the bot) or 'both'. What run receives follows it.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.
Fields
ModalFields
fields.reason): letters, digits and _.
ModalField
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.A help text under the label (100 characters at most): a text, or a function of
t and the data.TextField
A text the person types.The text shown while the field is empty (100 characters at most): a text, or a function of
t and the data.SelectField
A menu of texts you declare.The options (25 at most), written like the options of a select menu.
The text shown when nothing is picked (150 characters at most): a text, or a function of
t and the data.EntityField
A menu of users, roles, users and roles, or channels of the server.The text shown when nothing is picked (150 characters at most): a text, or a function of
t and the data.FilesField
Files the person uploads.The kinds of files accepted:
'image', 'video', 'audio', or extensions like '.pdf' (10 at most).RadioField
One choice among a few, shown as radio buttons. Discord documentationCheckboxesField
Several choices among a few, shown as checkboxes. Discord documentationCheckboxField
One checkbox: yes or no. Discord documentationNoteField
A text shown in the form, which nobody fills in. Discord documentationWhat run receives
ModalContext
Whatrun receives when the form is sent: the place as PlaceOf gives it with a ModalInteraction, and:
FieldValuesOf
FieldValue
Whatrun receives for a field, from its declaration:
Discord documentation