mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
feat(website): Show constructor information (#8540)
This commit is contained in:
@@ -59,7 +59,7 @@ export class ActionRowBuilder<T extends AnyComponentBuilder> extends ComponentBu
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIActionRowComponent<ReturnType<T['toJSON']>> {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
@@ -23,7 +23,11 @@ export abstract class ComponentBuilder<
|
||||
public readonly data: Partial<DataType>;
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* Serializes this component to an API-compatible JSON object
|
||||
*
|
||||
* @remarks
|
||||
* This method runs validations on the data before serializing it.
|
||||
* As such, it may throw an error if the data is invalid.
|
||||
*/
|
||||
public abstract toJSON(): AnyAPIActionRowComponent;
|
||||
|
||||
|
||||
@@ -21,6 +21,35 @@ import { ComponentBuilder } from '../Component';
|
||||
* Represents a button component
|
||||
*/
|
||||
export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Creates a new button from API data
|
||||
* @param data - The API data to create this button with
|
||||
*
|
||||
* @example
|
||||
* Creating a button from an API data object
|
||||
* ```ts
|
||||
* const button = new ButtonBuilder({
|
||||
* style: 'primary',
|
||||
* label: 'Click Me',
|
||||
* emoji: {
|
||||
* name: ':smile:',
|
||||
* id: '12345678901234567890123456789012',
|
||||
* },
|
||||
* custom_id: '12345678901234567890123456789012',
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* Creating a button using setters and API data
|
||||
* ```ts
|
||||
* const button = new ButtonBuilder({
|
||||
* style: 'primary',
|
||||
* label: 'Click Me',
|
||||
* })
|
||||
* .setEmoji({ name: ':smile:', id: '12345678901234567890123456789012' })
|
||||
* .setCustomId('12345678901234567890123456789012');
|
||||
* ```
|
||||
*/
|
||||
public constructor(data?: Partial<APIButtonComponent>) {
|
||||
super({ type: ComponentType.Button, ...data });
|
||||
}
|
||||
@@ -38,6 +67,10 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Sets the URL for this button
|
||||
*
|
||||
* @remarks
|
||||
* This method is only available to buttons using the `Link` button style.
|
||||
* Only three types of URL schemes are currently supported: `https://`, `http://` and `discord://`
|
||||
*
|
||||
* @param url - The URL to open when this button is clicked
|
||||
*/
|
||||
public setURL(url: string) {
|
||||
@@ -48,6 +81,9 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
/**
|
||||
* Sets the custom id for this button
|
||||
*
|
||||
* @remarks
|
||||
* This method is only applicable to buttons that are not using the `Link` button style.
|
||||
*
|
||||
* @param customId - The custom id to use for this button
|
||||
*/
|
||||
public setCustomId(customId: string) {
|
||||
@@ -86,7 +122,7 @@ export class ButtonBuilder extends ComponentBuilder<APIButtonComponent> {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIButtonComponent {
|
||||
validateRequiredButtonParameters(
|
||||
|
||||
@@ -117,7 +117,7 @@ export class SelectMenuBuilder extends ComponentBuilder<APISelectMenuComponent>
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APISelectMenuComponent {
|
||||
validateRequiredSelectMenuParameters(this.options, this.data.custom_id);
|
||||
|
||||
@@ -65,7 +65,7 @@ export class SelectMenuOptionBuilder implements JSONEncodable<APISelectMenuOptio
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APISelectMenuOption {
|
||||
validateRequiredSelectMenuOptionParameters(this.data.label, this.data.value);
|
||||
|
||||
@@ -104,7 +104,7 @@ export class TextInputBuilder
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc JSONEncodable.toJSON}
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APITextInputComponent {
|
||||
validateRequiredParameters(this.data.custom_id, this.data.style, this.data.label);
|
||||
|
||||
@@ -35,7 +35,7 @@ export class ContextMenuCommandBuilder {
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @deprecated This property is deprecated and will be removed in the future.
|
||||
* You should use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* You should use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
|
||||
*/
|
||||
public readonly default_permission: boolean | undefined = undefined;
|
||||
|
||||
@@ -86,7 +86,7 @@ export class ContextMenuCommandBuilder {
|
||||
* @param value - Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
* @deprecated Use `setDefaultMemberPermissions` or `setDMPermission` instead.
|
||||
* @deprecated Use {@link ContextMenuCommandBuilder.setDefaultMemberPermissions} or {@link ContextMenuCommandBuilder.setDMPermission} instead.
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
|
||||
@@ -70,6 +70,9 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ComponentBuilder.toJSON}
|
||||
*/
|
||||
public toJSON(): APIModalInteractionResponseCallbackData {
|
||||
validateRequiredParameters(this.data.custom_id, this.data.title, this.components);
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
|
||||
@@ -14,6 +14,9 @@ export class SlashCommandIntegerOption
|
||||
{
|
||||
public readonly type = ApplicationCommandOptionType.Integer as const;
|
||||
|
||||
/**
|
||||
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
|
||||
*/
|
||||
public setMaxValue(max: number): this {
|
||||
numberValidator.parse(max);
|
||||
|
||||
@@ -22,6 +25,9 @@ export class SlashCommandIntegerOption
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
|
||||
*/
|
||||
public setMinValue(min: number): this {
|
||||
numberValidator.parse(min);
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ export class SlashCommandNumberOption
|
||||
{
|
||||
public readonly type = ApplicationCommandOptionType.Number as const;
|
||||
|
||||
/**
|
||||
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMaxValue}
|
||||
*/
|
||||
public setMaxValue(max: number): this {
|
||||
numberValidator.parse(max);
|
||||
|
||||
@@ -22,6 +25,9 @@ export class SlashCommandNumberOption
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc ApplicationCommandNumericOptionMinMaxValueMixin.setMinValue}
|
||||
*/
|
||||
public setMinValue(min: number): this {
|
||||
numberValidator.parse(min);
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ export class EmbedBuilder {
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @param fields The fields to add
|
||||
* @param fields - The fields to add
|
||||
*/
|
||||
public addFields(...fields: RestOrArray<APIEmbedField>): this {
|
||||
fields = normalizeArray(fields);
|
||||
@@ -120,9 +120,9 @@ export class EmbedBuilder {
|
||||
* embed.spliceFields(-1, 1);
|
||||
* ```
|
||||
*
|
||||
* @param index The index to start at
|
||||
* @param deleteCount The number of fields to remove
|
||||
* @param fields The replacing field objects
|
||||
* @param index - The index to start at
|
||||
* @param deleteCount - The number of fields to remove
|
||||
* @param fields - The replacing field objects
|
||||
*/
|
||||
public spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {
|
||||
// Ensure adding these fields won't exceed the 25 field limit
|
||||
@@ -144,7 +144,7 @@ export class EmbedBuilder {
|
||||
*
|
||||
* You can set a maximum of 25 fields.
|
||||
*
|
||||
* @param fields The fields to set
|
||||
* @param fields - The fields to set
|
||||
*/
|
||||
public setFields(...fields: RestOrArray<APIEmbedField>) {
|
||||
this.spliceFields(0, this.data.fields?.length ?? 0, ...normalizeArray(fields));
|
||||
@@ -154,7 +154,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the author of this embed
|
||||
*
|
||||
* @param options The options for the author
|
||||
* @param options - The options for the author
|
||||
*/
|
||||
|
||||
public setAuthor(options: EmbedAuthorOptions | null): this {
|
||||
@@ -173,7 +173,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the color of this embed
|
||||
*
|
||||
* @param color The color of the embed
|
||||
* @param color - The color of the embed
|
||||
*/
|
||||
public setColor(color: number | RGBTuple | null): this {
|
||||
// Data assertions
|
||||
@@ -191,7 +191,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the description of this embed
|
||||
*
|
||||
* @param description The description
|
||||
* @param description - The description
|
||||
*/
|
||||
public setDescription(description: string | null): this {
|
||||
// Data assertions
|
||||
@@ -204,7 +204,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the footer of this embed
|
||||
*
|
||||
* @param options The options for the footer
|
||||
* @param options - The options for the footer
|
||||
*/
|
||||
public setFooter(options: EmbedFooterOptions | null): this {
|
||||
if (options === null) {
|
||||
@@ -222,7 +222,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the image of this embed
|
||||
*
|
||||
* @param url The URL of the image
|
||||
* @param url - The URL of the image
|
||||
*/
|
||||
public setImage(url: string | null): this {
|
||||
// Data assertions
|
||||
@@ -235,7 +235,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the thumbnail of this embed
|
||||
*
|
||||
* @param url The URL of the thumbnail
|
||||
* @param url - The URL of the thumbnail
|
||||
*/
|
||||
public setThumbnail(url: string | null): this {
|
||||
// Data assertions
|
||||
@@ -248,7 +248,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the timestamp of this embed
|
||||
*
|
||||
* @param timestamp The timestamp or date
|
||||
* @param timestamp - The timestamp or date
|
||||
*/
|
||||
public setTimestamp(timestamp: number | Date | null = Date.now()): this {
|
||||
// Data assertions
|
||||
@@ -261,7 +261,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the title of this embed
|
||||
*
|
||||
* @param title The title
|
||||
* @param title - The title
|
||||
*/
|
||||
public setTitle(title: string | null): this {
|
||||
// Data assertions
|
||||
@@ -274,7 +274,7 @@ export class EmbedBuilder {
|
||||
/**
|
||||
* Sets the URL of this embed
|
||||
*
|
||||
* @param url The URL
|
||||
* @param url - The URL
|
||||
*/
|
||||
public setURL(url: string | null): this {
|
||||
// Data assertions
|
||||
|
||||
Reference in New Issue
Block a user