mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
docs(builders): Add some basic documentation (#9359)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { JSONEncodable } from '@discordjs/util';
|
||||
import type {
|
||||
APIActionRowComponent,
|
||||
@@ -10,11 +12,25 @@ import { createComponentBuilder } from '../../components/Components.js';
|
||||
import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js';
|
||||
import { titleValidator, validateRequiredParameters } from './Assertions.js';
|
||||
|
||||
/**
|
||||
* A builder that creates API-compatible JSON data for modals.
|
||||
*/
|
||||
export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCallbackData> {
|
||||
/**
|
||||
* The API data associated with this modal.
|
||||
*/
|
||||
public readonly data: Partial<APIModalInteractionResponseCallbackData>;
|
||||
|
||||
/**
|
||||
* The components within this modal.
|
||||
*/
|
||||
public readonly components: ActionRowBuilder<ModalActionRowComponentBuilder>[] = [];
|
||||
|
||||
/**
|
||||
* Creates a new modal from API data.
|
||||
*
|
||||
* @param data - The API data to create this modal with
|
||||
*/
|
||||
public constructor({ components, ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {
|
||||
this.data = { ...data };
|
||||
this.components = (components?.map((component) => createComponentBuilder(component)) ??
|
||||
@@ -22,9 +38,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title of the modal
|
||||
* Sets the title of this modal.
|
||||
*
|
||||
* @param title - The title of the modal
|
||||
* @param title - The title to use
|
||||
*/
|
||||
public setTitle(title: string) {
|
||||
this.data.title = titleValidator.parse(title);
|
||||
@@ -32,9 +48,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the custom id of the modal
|
||||
* Sets the custom id of this modal.
|
||||
*
|
||||
* @param customId - The custom id of this modal
|
||||
* @param customId - The custom id to use
|
||||
*/
|
||||
public setCustomId(customId: string) {
|
||||
this.data.custom_id = customIdValidator.parse(customId);
|
||||
@@ -42,9 +58,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds components to this modal
|
||||
* Adds components to this modal.
|
||||
*
|
||||
* @param components - The components to add to this modal
|
||||
* @param components - The components to add
|
||||
*/
|
||||
public addComponents(
|
||||
...components: RestOrArray<
|
||||
@@ -62,9 +78,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the components in this modal
|
||||
* Sets components for this modal.
|
||||
*
|
||||
* @param components - The components to set this modal to
|
||||
* @param components - The components to set
|
||||
*/
|
||||
public setComponents(...components: RestOrArray<ActionRowBuilder<ModalActionRowComponentBuilder>>) {
|
||||
this.components.splice(0, this.components.length, ...normalizeArray(components));
|
||||
|
||||
Reference in New Issue
Block a user