Skip to content

CreateModal

CreateModal creates a modal popup form that Discord displays to a user. Modals can contain 1–5 CreateActionRow<CreateTextInput> rows.

import { CreateModal, CreateActionRow, CreateTextInput, TextInputType } from "lunibee";

Sets the custom ID used to identify this modal when submitted (max 100 characters).

modal.setCustomId("ticket_modal");

Sets the modal window title (max 45 characters).

modal.setTitle("Open a Support Ticket");

Adds CreateActionRow<CreateTextInput> rows to the modal (1–5). Throws a TypeError when called with none and a RangeError past five rows.

modal.addComponents(
new CreateActionRow<CreateTextInput>().addComponents(
new CreateTextInput()
.setCustomId("subject")
.setLabel("Subject")
.setStyle(TextInputType.Short)
.setRequired(true),
),
);

Serializes to a raw Discord API-compatible modal object. Throws when the custom ID or title is missing, or when the modal has no components.


Method Description
setCustomId(id) Unique ID for this field (used in getRequiredInputValue(); max 100 chars). Required: toJSON() throws without it.
setLabel(label) The visible field label (max 45 chars).
setStyle(style) TextInputType.Short (single line, the default) or TextInputType.Paragraph (multi-line).
setRequired(required?) Whether the field is required (required defaults to true).
setValue(value) Pre-filled default value (max 4000 chars).
setPlaceholder(text) Placeholder text (max 100 chars).
setMinLength(min) Minimum character length (0–4000).
setMaxLength(max) Maximum character length (0–4000). toJSON() throws when min_length exceeds max_length.
toJSON() Serializes the text input.
import {
CreateModal,
CreateActionRow,
CreateTextInput,
TextInputType,
} from "lunibee";
// Build the modal
const modal = new CreateModal()
.setCustomId("report_form")
.setTitle("Report a User")
.addComponents(
new CreateActionRow<CreateTextInput>().addComponents(
new CreateTextInput()
.setCustomId("reported_user")
.setLabel("Reported User ID or Username")
.setStyle(TextInputType.Short)
.setRequired(true),
),
new CreateActionRow<CreateTextInput>().addComponents(
new CreateTextInput()
.setCustomId("reason")
.setLabel("Reason for reporting")
.setStyle(TextInputType.Paragraph)
.setRequired(true)
.setMaxLength(1000),
),
);
// Show the modal in response to a command
client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "report") return;
await interaction.showModal(modal);
});
// Handle the modal submission
client.on("interactionCreate", async (interaction) => {
if (!interaction.isModalSubmit() || interaction.customId !== "report_form") return;
const userId = interaction.getRequiredInputValue("reported_user");
const reason = interaction.getRequiredInputValue("reason");
await interaction.reply({
content: `📨 Report filed for **${userId}**: ${reason}`,
ephemeral: true,
});
});

Adds text inputs, each in its own action row (the layout Discord requires), so you do not build the rows yourself. A modal holds at most five.

new CreateModal()
.setCustomId("feedback")
.setTitle("Feedback")
.addTextInputs(
new CreateTextInput().setCustomId("title").setLabel("Subject").setStyle(TextInputType.Short),
new CreateTextInput().setCustomId("body").setLabel("Details").setStyle(TextInputType.Paragraph),
);

toJSON() is now typed with a required custom_id and title, matching what it validates.