On This Page

EmbedBuilder

Class in Builders and Formatting · JavaScript & TypeScript

Assemble an embed by chaining methods, then pass the builder or build()'s plain object in a message operation's embeds

A message operation builds a supplied builder once when it reads its input, so later changes do not affect that operation. Setters change this builder and return it so calls can be chained. Later setters replace earlier values, while field methods append. Every build returns a fresh object, including copied author, footer, media and field objects. The builder reads supported properties by name, including inherited properties and getters that do not appear in normal key lists. Values that are not objects and unknown own enumerable fields remain for the message operation to validate. Building sends nothing. Only color and timestamp convert their input, throwing HelperError for input they cannot convert. The field method throws ConfigurationError for options that are not an object with an optional boolean inline. Message operations check lengths, URLs and server limits

class EmbedBuilder

Constructor#

new EmbedBuilder(): EmbedBuilder

Methods#

addFields#

Add field objects after existing fields in argument order and return this builder

Copies each object, passing no arguments adds nothing

addFields(...values: readonly EmbedFieldInput[]): thisaddFields(
  ...values:
    readonly EmbedFieldInput[]
): this

Parameters

...values
readonly EmbedFieldInput[]
Returns
this

author#

Replace the author label and optional links, copy the supplied object, then return this builder

author(value: EmbedAuthorInput): thisauthor(
  value: EmbedAuthorInput
): this

Parameters

Returns
this

build#

Return a fresh plain input snapshot for messages.send, messages.reply or messages.edit

This method performs no URL, length, attachment or provider-limit validation

build(): EmbedInput
Returns
EmbedInput

color#

Replace the color and return this builder

Accepts any ColorInput, such as 0xff8800, "#ff8800" or [255, 136, 0], converted with colors.parse. Input that cannot be converted throws HelperError with operation embed.color

color(value: ColorInput): this

Parameters

Returns
this

description#

Replace the body text and return this builder

Message operations enforce the 4096-character limit

description(value: string): this

Parameters

value
string
Returns
this

field#

Add a named section after existing fields and return this builder

Set options.inline to true to request side-by-side display. It defaults to false when the message is sent. Options that are not an object, or an inline value that is not a boolean, throw ConfigurationError

field(
    name: string,
    value: string,
    options?: EmbedFieldOptions
): thisfield(
  name: string,
  value: string,
  options?: EmbedFieldOptions
): this

Parameters

name
string
value
string
options optional
EmbedFieldOptions
Returns
this

Replace the footer text and optional icon, copy the supplied object, then return this builder

footer(value: EmbedFooterInput): thisfooter(
  value: EmbedFooterInput
): this

Parameters

Returns
this

image#

Replace the full-size image URL and optional alternative text, copy the object, then return this builder

No image is uploaded or fetched

image(value: EmbedMediaInput): this

Parameters

Returns
this

thumbnail#

Replace the small image URL and optional alternative text, copy the object, then return this builder

No image is uploaded or fetched

thumbnail(value: EmbedMediaInput): thisthumbnail(
  value: EmbedMediaInput
): this

Parameters

Returns
this

timestamp#

Replace the embed's timestamp and return this builder

Accepts a Date, Unix epoch milliseconds or an ISO 8601 string with a timezone. A Date or number is converted with toISOString, and a string is kept for the message operation to validate. An invalid Date or a number outside the Date range throws HelperError with operation embed.timestamp

timestamp(value: string | number | Date): thistimestamp(
  value: string | number | Date
): this

Parameters

value
string | number | Date
Returns
this

title#

Replace the title text and return this builder

Message operations enforce the 256-character limit

title(value: string): this

Parameters

value
string
Returns
this

url#

Replace the destination opened from the title and return this builder

The URL is not checked or fetched here

url(value: string): this

Parameters

value
string
Returns
this