mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
docs(builders/components): document constructors (#8636)
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
/* eslint-disable jsdoc/check-param-names */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type APIActionRowComponent,
|
type APIActionRowComponent,
|
||||||
ComponentType,
|
ComponentType,
|
||||||
@@ -33,6 +35,40 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
|||||||
*/
|
*/
|
||||||
public readonly components: T[];
|
public readonly components: T[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new action row from API data
|
||||||
|
*
|
||||||
|
* @param data - The API data to create this action row with
|
||||||
|
* @example
|
||||||
|
* Creating an action row from an API data object
|
||||||
|
* ```ts
|
||||||
|
* const actionRow = new ActionRowBuilder({
|
||||||
|
* components: [
|
||||||
|
* {
|
||||||
|
* custom_id: "custom id",
|
||||||
|
* label: "Type something",
|
||||||
|
* style: TextInputStyle.Short,
|
||||||
|
* type: ComponentType.TextInput,
|
||||||
|
* },
|
||||||
|
* ],
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* Creating an action row using setters and API data
|
||||||
|
* ```ts
|
||||||
|
* const actionRow = new ActionRowBuilder({
|
||||||
|
* components: [
|
||||||
|
* {
|
||||||
|
* custom_id: "custom id",
|
||||||
|
* label: "Click me",
|
||||||
|
* style: ButtonStyle.Primary,
|
||||||
|
* type: ComponentType.Button,
|
||||||
|
* },
|
||||||
|
* ],
|
||||||
|
* })
|
||||||
|
* .addComponents(button2, button3);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
|
public constructor({ components, ...data }: Partial<APIActionRowComponent<APIActionRowComponentTypes>> = {}) {
|
||||||
super({ type: ComponentType.ActionRow, ...data });
|
super({ type: ComponentType.ActionRow, ...data });
|
||||||
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];
|
this.components = (components?.map((component) => createComponentBuilder(component)) ?? []) as T[];
|
||||||
|
|||||||
@@ -29,24 +29,24 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
|||||||
* Creating a button from an API data object
|
* Creating a button from an API data object
|
||||||
* ```ts
|
* ```ts
|
||||||
* const button = new ButtonBuilder({
|
* const button = new ButtonBuilder({
|
||||||
* style: 'primary',
|
* custom_id: 'a cool button',
|
||||||
|
* style: ButtonStyle.Primary,
|
||||||
* label: 'Click Me',
|
* label: 'Click Me',
|
||||||
* emoji: {
|
* emoji: {
|
||||||
* name: ':smile:',
|
* name: 'smile',
|
||||||
* id: '12345678901234567890123456789012',
|
* id: '123456789012345678',
|
||||||
* },
|
* },
|
||||||
* custom_id: '12345678901234567890123456789012',
|
|
||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
* @example
|
* @example
|
||||||
* Creating a button using setters and API data
|
* Creating a button using setters and API data
|
||||||
* ```ts
|
* ```ts
|
||||||
* const button = new ButtonBuilder({
|
* const button = new ButtonBuilder({
|
||||||
* style: 'primary',
|
* style: ButtonStyle.Secondary,
|
||||||
* label: 'Click Me',
|
* label: 'Click Me',
|
||||||
* })
|
* })
|
||||||
* .setEmoji({ name: ':smile:', id: '12345678901234567890123456789012' })
|
* .setEmoji({ name: '🙂' })
|
||||||
* .setCustomId('12345678901234567890123456789012');
|
* .setCustomId('another cool button');
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public constructor(data?: Partial<APIButtonComponent>) {
|
public constructor(data?: Partial<APIButtonComponent>) {
|
||||||
|
|||||||
@@ -21,6 +21,37 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
|||||||
*/
|
*/
|
||||||
public readonly options: SelectMenuOptionBuilder[];
|
public readonly options: SelectMenuOptionBuilder[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new select menu from API data
|
||||||
|
*
|
||||||
|
* @param data - The API data to create this select menu with
|
||||||
|
* @example
|
||||||
|
* Creating a select menu from an API data object
|
||||||
|
* ```ts
|
||||||
|
* const selectMenu = new SelectMenuBuilder({
|
||||||
|
* custom_id: 'a cool select menu',
|
||||||
|
* placeholder: 'select an option',
|
||||||
|
* max_values: 2,
|
||||||
|
* options: [
|
||||||
|
* { label: 'option 1', value: '1' },
|
||||||
|
* { label: 'option 2', value: '2' },
|
||||||
|
* { label: 'option 3', value: '3' },
|
||||||
|
* ],
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* Creating a select menu using setters and API data
|
||||||
|
* ```ts
|
||||||
|
* const selectMenu = new SelectMenuBuilder({
|
||||||
|
* custom_id: 'a cool select menu',
|
||||||
|
* })
|
||||||
|
* .setMinValues(1)
|
||||||
|
* .addOptions({
|
||||||
|
* label: 'Catchy',
|
||||||
|
* value: 'catch',
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public constructor(data?: Partial<APISelectMenuComponent>) {
|
public constructor(data?: Partial<APISelectMenuComponent>) {
|
||||||
const { options, ...initData } = data ?? {};
|
const { options, ...initData } = data ?? {};
|
||||||
super({ type: ComponentType.SelectMenu, ...initData });
|
super({ type: ComponentType.SelectMenu, ...initData });
|
||||||
|
|||||||
@@ -11,6 +11,28 @@ import {
|
|||||||
* Represents a option within a select menu component
|
* Represents a option within a select menu component
|
||||||
*/
|
*/
|
||||||
export class SelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
|
export class SelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOption> {
|
||||||
|
/**
|
||||||
|
* Creates a new select menu option from API data
|
||||||
|
*
|
||||||
|
* @param data - The API data to create this select menu option with
|
||||||
|
* @example
|
||||||
|
* Creating a select menu option from an API data object
|
||||||
|
* ```ts
|
||||||
|
* const selectMenuOption = new SelectMenuOptionBuilder({
|
||||||
|
* label: 'catchy label',
|
||||||
|
* value: '1',
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* Creating a select menu option using setters and API data
|
||||||
|
* ```ts
|
||||||
|
* const selectMenuOption = new SelectMenuOptionBuilder({
|
||||||
|
* default: true,
|
||||||
|
* value: '1',
|
||||||
|
* })
|
||||||
|
* .setLabel('woah')
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public constructor(public data: Partial<APISelectMenuOption> = {}) {}
|
public constructor(public data: Partial<APISelectMenuOption> = {}) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,6 +19,29 @@ export class TextInputBuilder
|
|||||||
extends ComponentBuilder<APITextInputComponent>
|
extends ComponentBuilder<APITextInputComponent>
|
||||||
implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>>
|
implements Equatable<APITextInputComponent | JSONEncodable<APITextInputComponent>>
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Creates a new text input from API data
|
||||||
|
*
|
||||||
|
* @param data - The API data to create this text input with
|
||||||
|
* @example
|
||||||
|
* Creating a select menu option from an API data object
|
||||||
|
* ```ts
|
||||||
|
* const textInput = new TextInputBuilder({
|
||||||
|
* custom_id: 'a cool select menu',
|
||||||
|
* label: 'Type something',
|
||||||
|
* style: TextInputStyle.Short,
|
||||||
|
* });
|
||||||
|
* ```
|
||||||
|
* @example
|
||||||
|
* Creating a select menu option using setters and API data
|
||||||
|
* ```ts
|
||||||
|
* const textInput = new TextInputBuilder({
|
||||||
|
* label: 'Type something else',
|
||||||
|
* })
|
||||||
|
* .setCustomId('woah')
|
||||||
|
* .setStyle(TextInputStyle.Paragraph);
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
public constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {
|
public constructor(data?: APITextInputComponent & { type?: ComponentType.TextInput }) {
|
||||||
super({ type: ComponentType.TextInput, ...data });
|
super({ type: ComponentType.TextInput, ...data });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user