Modal
Represents a modal for user interactions.
Signature
export declare class ModalJSDoc
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
data: Partial<APIModalInteractionResponseCallbackData>;components: ModalBuilderComponents[];Methods
constructorConstructorconstructor(data?: Partial<APIModalInteractionResponseCallbackData>);addComponents(...components: RestOrArray<ModalBuilderComponents>): this;Adds components to the modal.
Parameters
components- Components to be added to the modal.
Returns
The current Modal instance.
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.
toJSON(): APIModalInteractionResponseCallbackData;Converts the modal to JSON format.
Returns
The modal data in JSON format.