ButtonBuilder class

const button = new ButtonBuilder(data?: object);

constructor

The constructor provides one optional argument which is an object which provides the data for the ButtonBuilder class.

The object may contain the following information:

  • custom_id: An id so you can recognize the button when it's being pressed by a member. The id must be unique and a string between 1-100 characters.

  • style: A number which defines which kind of style the button should have.

  • label: The text which should be on the button. The string must be between 1-100 characters.

  • emoji: An object which defines the emoji which should be on the button, if you want an emoji on the button. The object should provide whether the emoji is animated or not, the id of the emoji and the name of the emoji.

  • disabled: A boolean which defines whether the button can be pressed or not.

  • url: A url for the member to go to when the member presses the button.

  • type: A number which defines the type of component of the button. (2 means it's a button)

Properties

data

An object which makes it a valid object for the Discord API.

{
    custom_id?: string;
    style: number;
    label: string;
    emoji?: {
        animated: boolean;
        id?: string;
        name: string;
    }
    disabled: boolean;
    url?: string;
    type: number;
}

Functions

setCustomId

button.setCustomId(customId: string) : ButtonBuilder;

Sets a custom id for the button which will be returned to the bot once the button is pressed and makes you able to recognize the button. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setDisabled

button.setDisabled(disabled?: boolean) : ButtonBuilder;

Defines whether the button may be pressed by a member or not. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setLabel

button.setLabel(label: string) : ButtonBuilder;

Sets a label for the button which is visible to server members. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setText

button.setText(text: string) : ButtonBuilder;

Identical to the setLabel function. Sets a label for the button which is visible to server members. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setStyle

button.setStyle(style: string | number) : ButtonBuilder;

Sets the style for the button and defines how the button will look like. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setURL

button.setURL(url: string) : ButtonBuilder;

Sets a url for the button so when a member presses the button, the member will be redirected to the website. When setting the url, the style type will automatically change to a url button style. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

setEmoji

button.setEmoji(string | Emoji) : ButtonBuilder;

Adds an emoji to the button. The emoji must be a unicode emoji or an instance of the Emoji class. The function returns the same ButtonBuilder class so you don't have to declare it everytime again.

toJSON

Converts the ButtonBuilder class to an object to make it a valid object for the Discord API. The function returns the same data as the data property.

{
    custom_id?: string;
    style: number;
    label: string;
    emoji?: {
        animated: boolean;
        id?: string;
        name: string;
    }
    disabled: boolean;
    url?: string;
    type: number;
}

Last updated