Modal

Represents a modal for user interactions.

Signature

export declare class Modal
JSDoc
Examples
const modal = new Modal();
modal.setTitle("Sample Modal");
modal.setCustomId("sample-modal");
modal.addComponents(
  new Label()
    .setLabel("Enter text")
    .setComponent(
      new TextInput()
        .setCustomId("sample-input")
        .setStyle(TextInputStyle.Paragraph)
    )
);
modal.run((interaction) => {
  // Handle modal submission
});
const json = modal.toJSON();
@templateT - The type of components allowed in the modal.

Properties

Methods

setComponents(component: ModalBuilderComponents[]): this;

Set the components to the modal.

Parameters
component
The components to set into the modal.
Returns

The current Modal instance.

setTitle(title: string): this;

Sets the title of the modal.

Parameters
title
The title of the modal.
Returns

The current Modal instance.

setCustomId(id: string): this;

Sets the custom ID of the modal.

Parameters
id
The custom ID for the modal.
Returns

The current Modal instance.

run(func: ModalSubmitCallback): this;

Sets the callback function to be executed when the modal is submitted.

Parameters
func
The callback function.
Returns

The current Modal instance.