Skip to content

A modal is a form the client shows over the conversation. Open one in answer to a command or a component click. A modal has a custom id, a title (≤ 45 characters) and 1–5 top-level items: labels, each wrapping one input (text input, select, radio group, checkbox group, checkbox or file upload), and text displays.

import {
LabelBuilder, ModalBuilder, StringSelectMenuBuilder, TextDisplayBuilder, TextInputBuilder,
TextInputStyle,
} from '@zaun/bot';
interaction.showModal(new ModalBuilder().setCustomId('report').setTitle('Report a problem')
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Tell us what happened. Moderators will read it.'))
.addTextInput('Summary', new TextInputBuilder().setCustomId('summary').setStyle(TextInputStyle.Short).setMinLength(5).setMaxLength(80))
.addTextInput('Details', new TextInputBuilder().setCustomId('details').setStyle(TextInputStyle.Paragraph).setRequired(false))
.addLabelComponents(new LabelBuilder().setLabel('Area').setComponent(
new StringSelectMenuBuilder().setCustomId('area').addOptions({ label: 'Chat', value: 'chat' }, { label: 'Voice', value: 'voice' }))));
bot.modal('report', (interaction) => {
const summary = interaction.fields.getTextInputValue('summary');
const details = interaction.fields.getTextInputValue('details') || '(none)';
const area = interaction.fields.getStringSelectValues('area')[0];
interaction.reply({ content: `Thanks! We got: ${summary} (${area})`, ephemeral: true });
});

Also getRadioValue, getCheckbox, getSelectedMembers and getUploadedFiles.

A text input gives its text; a checkbox gives "true" or "false"; selects, radio and checkbox groups give their chosen values; a file upload gives attachment ids.

The host checks every submission against the modal it showed: required inputs present, lengths and counts in bounds, choices among the options. A modal can be submitted once, by the member it was shown to, within 15 minutes.

See the feedback form example.