Discord.https - v3.0.16
    Preparing search index...

    Class ButtonBuilder

    A builder that creates API-compatible JSON data for buttons.

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new button from API data.

      Parameters

      Returns ButtonBuilder

      Creating a button from an API data object:

      const button = new ButtonBuilder({
      custom_id: 'a cool button',
      style: ButtonStyle.Primary,
      label: 'Click Me',
      emoji: {
      name: 'smile',
      id: '123456789012345678',
      },
      });

      Creating a button using setters and API data:

      const button = new ButtonBuilder({
      style: ButtonStyle.Secondary,
      label: 'Click Me',
      })
      .setEmoji({ name: '🙂' })
      .setCustomId('another cool button');

    Properties

    data: Partial<APIButtonComponent>

    The API data associated with this component.

    Methods

    • Clears the id of this component, defaulting to a default incremented id.

      Returns this

    • Sets the custom id for this button.

      Parameters

      • customId: string

        The custom id to use

      Returns this

      This method is only applicable to buttons that are not using the Link button style.

    • Sets whether this button is disabled.

      Parameters

      • Optionaldisabled: boolean

        Whether to disable this button

      Returns this

    • Sets the id (not the custom id) for this component.

      Parameters

      • id: number

        The id for this component

      Returns this

    • Sets the label for this button.

      Parameters

      • label: string

        The label to use

      Returns this

    • Sets the SKU id that represents a purchasable SKU for this button.

      Parameters

      • skuId: string

        The SKU id to use

      Returns this

      Only available when using premium-style buttons.

    • Sets the style of this button.

      Parameters

      Returns this

    • Sets the URL for this button.

      Parameters

      • url: string

        The URL to use

      Returns this

      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://.

    • Serializes this builder to API-compatible JSON data.

      Returns APIButtonComponent

      This method runs validations on the data before serializing it. As such, it may throw an error if the data is invalid.