ModalBuilder

export declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData>
export declare class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData>
A builder that creates API-compatible JSON data for modals.
constructor(data?)
Creates a new modal from API data.
NameTypeOptionalDescription
dataPartial<APIModalInteractionResponseCallbackData>YesThe API data to create this modal with
The components within this modal.
The API data associated with this modal.
Deprecated
addActionRowComponents(...components):this
Use addLabelComponents instead
Deprecated
Adds action rows to this modal.
Deprecated
addComponents(...components):this
Adds components to this modal.
addLabelComponents(...components):this
Adds label components to this modal.
NameTypeOptionalDescription
...componentsRestOrArray<APILabelComponent | LabelBuilder | ((builder: LabelBuilder) => LabelBuilder)>NoThe components to add
Deprecated
setComponents(...components):this
Use setLabelComponents instead
Deprecated
Sets components for this modal.
NameTypeOptionalDescription
...componentsRestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder> | LabelBuilder>NoThe components to set
setCustomId(customId):this
Sets the custom id of this modal.
NameTypeOptionalDescription
customIdstringNoThe custom id to use
setLabelComponents(...components):this
Sets the labels for this modal.
NameTypeOptionalDescription
...componentsRestOrArray<APILabelComponent | LabelBuilder | ((builder: LabelBuilder) => LabelBuilder)>NoThe components to set
setTitle(title):this
Sets the title of this modal.
NameTypeOptionalDescription
titlestringNoThe title to use
spliceLabelComponents(index, deleteCount, ...labels):this
Removes, replaces, or inserts labels for this modal.
Remarks
This method behaves similarly to Array.prototype.splice(). The maximum amount of labels that can be added is 5.It's useful for modifying and adjusting order of the already-existing labels of a modal.
Example
Remove the first label:
modal.spliceLabelComponents(0, 1);
modal.spliceLabelComponents(0, 1);
Example
Remove the first n labels:
const n = 4;
modal.spliceLabelComponents(0, n);
const n = 4;
modal.spliceLabelComponents(0, n);
Example
Remove the last label:
modal.spliceLabelComponents(-1, 1);
modal.spliceLabelComponents(-1, 1);
NameTypeOptionalDescription
indexnumberNoThe index to start at
deleteCountnumberNoThe number of labels to remove
...labels(APILabelComponent | LabelBuilder | ((builder: LabelBuilder) => LabelBuilder))[]NoThe replacing label objects
Serializes this builder to API-compatible JSON data.
Remarks
This method runs validations on the data before serializing it. As such, it may throw an error if the data is invalid.