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

Hierarchy (View Summary)

Constructors

  • Creates a new embed from API data.

    Parameters

    • Optionaldata: APIEmbed

      The API data to create this embed with

    Returns EmbedBuilder

Properties

data: APIEmbed

The API data associated with this embed.

Methods

  • Appends fields to the embed.

    Parameters

    Returns this

    This method accepts either an array of fields or a variable number of field parameters. The maximum amount of fields that can be added is 25.

    Using an array:

    const fields: APIEmbedField[] = ...;
    const embed = new EmbedBuilder()
    .addFields(fields);

    Using rest parameters (variadic):

    const embed = new EmbedBuilder()
    .addFields(
    { name: 'Field 1', value: 'Value 1' },
    { name: 'Field 2', value: 'Value 2' },
    );
  • Sets the author of this embed.

    Parameters

    Returns this

  • Sets the color of this embed.

    Parameters

    • color: null | number | RGBTuple

      The color to use

    Returns this

  • Sets the description of this embed.

    Parameters

    • description: null | string

      The description to use

    Returns this

  • Sets the fields for this embed.

    Parameters

    Returns this

    This method is an alias for EmbedBuilder.spliceFields. More specifically, it splices the entire array of fields, replacing them with the provided fields.

    You can set a maximum of 25 fields.

  • Sets the footer of this embed.

    Parameters

    Returns this

  • Sets the image of this embed.

    Parameters

    • url: null | string

      The image URL to use

    Returns this

  • Sets the thumbnail of this embed.

    Parameters

    • url: null | string

      The thumbnail URL to use

    Returns this

  • Sets the timestamp of this embed.

    Parameters

    • Optionaltimestamp: null | number | Date

      The timestamp or date to use

    Returns this

  • Sets the title for this embed.

    Parameters

    • title: null | string

      The title to use

    Returns this

  • Sets the URL of this embed.

    Parameters

    • url: null | string

      The URL to use

    Returns this

  • Removes, replaces, or inserts fields for this embed.

    Parameters

    • index: number

      The index to start at

    • deleteCount: number

      The number of fields to remove

    • ...fields: APIEmbedField[]

      The replacing field objects

    Returns this

    This method behaves similarly to Array.prototype.splice(). The maximum amount of fields that can be added is 25.

    It's useful for modifying and adjusting order of the already-existing fields of an embed.

    Remove the first field:

    embed.spliceFields(0, 1);
    

    Remove the first n fields:

    const n = 4;
    embed.spliceFields(0, n);

    Remove the last field:

    embed.spliceFields(-1, 1);
    
  • Serializes this builder to API-compatible JSON data.

    Returns APIEmbed

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