Skip to main content

Modals

A modal is a pop-up form. Your bot shows it, the user fills it in, and your bot receives everything they entered at once. It is the right tool whenever a slash command would need more than two or three options, or when the answer should stay private.

Show the whole Modals flyout

The Modals subcategory

warning

A modal can only be shown in response to an interaction: a slash command, a button click, a select menu, or a context menu. It cannot be shown from a message event or on a timer.

A modal also cannot be shown in response to another modal, and it cannot be shown after you have already replied or deferred.

Showing a modal​

Show modal

show modal displays it. This is your response to the interaction, so do not reply or defer before it.

Create modal

create modal with title ... custom ID ... components ... builds the form. The custom ID is how you recognize the submission later.

tip

Right-click show modal or create modal and choose Preview Modal to see the form as Discord will draw it. See Message and Modal Previews.

Building the form​

Add component with label

add component with label is the wrapper around every input. It gives the field its label and an optional description, and holds the input itself.

Add text to the modal

add text to the modal adds a paragraph of explanation with no input attached.

A modal holds up to 5 of these.

The inputs​

Plug one of these into a label block.

BlockWhat the user does
text inputTypes text. Short for one line, paragraph for many.
select menuPicks from options you define.
user selectPicks members.
role selectPicks roles.
mentionable selectPicks members or roles.
channel selectPicks channels. Restrict the kinds with channel type blocks.
file uploadUploads between 1 and 10 files.
radio buttonsPicks exactly one of 2 to 10 choices.
checkboxesChecks any number of choices.
single checkboxChecks one box, for a yes or no.

Every input has a custom ID, which is how you read its value back. They have to be unique within the modal.

Options​

Select option

add an option fills a select menu: label, description, emoji, value, and whether it starts selected.

Choice option

add an option for radio buttons and checkboxes: label, description, value, and whether it starts selected.

Handling the submission​

When a modal is submitted

when a modal is submitted fires for every modal your bot shows, so check the custom ID first.

Custom ID of the modal User that submitted

custom ID of the modal and user that submited the modal tell you which form came back and who sent it.

Reading the values​

Each input type has its own block. Give it the custom ID you set on the input.

BlockReturns
text valueThe text from a text input.
select valuesThe values chosen in a select menu.
selected usersThe users chosen.
selected membersThe same people, as members of the server.
selected rolesThe roles chosen.
selected channelsThe channels chosen.
selected mentionablesThe users and roles chosen.
uploaded filesLinks to the files uploaded.
radio valueThe value of the radio button chosen.
checkbox valuesThe values of the boxes checked.
single checkboxTrue when the box was checked.

Most of these return a list, so read them with the Lists blocks.

Replying​

A modal submission is an interaction like any other, and it has the same 3 second limit. Use reply to the interaction, or defer reply and then edit the bot's reply.

A worked example: a suggestion form​

  1. Register a slash command suggest with no options.
  2. In the handler, show modal with create modal:
    • title "New suggestion", custom ID suggestion_form
    • a label "Title" holding a short text input, custom ID title
    • a label "Details" holding a paragraph text input, custom ID details
    • a label "Category" holding a select menu, custom ID category, with options for Feature, Bug and Other
  3. In when a modal is submitted:
    • Check the custom ID is suggestion_form.
    • Read the three values.
    • Send a message to your suggestions channel with a container holding the title, the category and the details.
    • React to it with 👍 and 👎.
    • Reply, visible only to the user, with "Thanks, your suggestion has been posted."
tip

Modals are much friendlier than a slash command with six options. The user sees labels and descriptions, and nothing they type is visible in the channel while they type it.