EmbedBuilder
Builder system used to buildMessageEmbed objects. Embeds allow you to send rich, formatted messages with titles, descriptions, fields, images, and more.
Constructor
EmbedBuilder()
Constructs a new EmbedBuilder instance.EmbedBuilder(EmbedBuilder builder)
Creates an EmbedBuilder using fields from an existing builder.EmbedBuilder(MessageEmbed embed)
Creates an EmbedBuilder using fields from an existing embed.Static Methods
fromData(DataObject data)
Creates an instance from a serializedDataObject. This is the inverse of MessageEmbed.toData().
Builder Methods
setTitle(String title)
Sets the title of the embed. Parameters:title- The title text (max 256 characters)
setTitle(String title, String url)
Sets the title with a clickable URL. Parameters:title- The title text (max 256 characters)url- The URL the title links to (must be http/https)
setUrl(String url)
Sets the URL of the embed. Used with title for clickable hyperlinks. If multiple embeds in a message use the same URL, Discord merges them into a gallery view. Parameters:url- The URL (must be http/https, max 2048 characters)
setDescription(CharSequence description)
Sets the description of the embed. This is the main text content. Parameters:description- The description text (max 4096 characters)
appendDescription(CharSequence description)
Appends text to the existing description. Parameters:description- The text to append (total max 4096 characters)
getDescriptionBuilder()
Returns theStringBuilder used to build the description. Useful for advanced manipulation.
Returns: StringBuilder with current description
setColor(Color color)
Sets the color of the embed’s side bar. Parameters:color- The color (usenullfor default)
setColor(int color)
Sets the color using a raw RGB integer value. Parameters:color- The raw RGB value
setTimestamp(TemporalAccessor temporal)
Sets the timestamp shown at the bottom of the embed. Parameters:temporal- The timestamp (typicallyInstantorOffsetDateTime)
setThumbnail(String url)
Sets a small thumbnail image in the top-right corner. Parameters:url- The image URL (http/https orattachment://filename.ext)
setImage(String url)
Sets a large image displayed in the embed body. Parameters:url- The image URL (http/https orattachment://filename.ext)
setAuthor(String name)
Sets the author name displayed at the top of the embed. Parameters:name- The author name (max 256 characters)
setAuthor(String name, String url)
Sets the author with a clickable URL. Parameters:name- The author name (max 256 characters)url- The URL the name links to (must be http/https)
setAuthor(String name, String url, String iconUrl)
Sets the author with a URL and icon. Parameters:name- The author name (max 256 characters)url- The URL the name links to (must be http/https)iconUrl- The icon image URL (http/https orattachment://)
setFooter(String text)
Sets the footer text displayed at the bottom of the embed. Parameters:text- The footer text (max 2048 characters)
setFooter(String text, String iconUrl)
Sets the footer with an icon. Parameters:text- The footer text (max 2048 characters)iconUrl- The icon image URL (http/https orattachment://)
addField(String name, String value, boolean inline)
Adds a field to the embed. Fields are displayed in rows. Parameters:name- The field name/title (max 256 characters)value- The field value/content (max 1024 characters)inline- Whether the field displays inline with others
addField(MessageEmbed.Field field)
Adds a field object to the embed. Parameters:field- The field to add
addBlankField(boolean inline)
Adds an empty field for spacing. Parameters:inline- Whether the blank field is inline
clearFields()
Removes all fields from the embed. Returns: The builder instancegetFields()
Returns a modifiable list of the embed’s fields. Returns: MutableList<MessageEmbed.Field>
clear()
Resets the builder to default state, removing all content. Returns: The builder instancecopyFrom(EmbedBuilder builder)
Copies all data from another builder. Parameters:builder- The builder to copy from
copyFrom(MessageEmbed embed)
Copies all data from an existing embed. Parameters:embed- The embed to copy from
Validation Methods
isEmpty()
Checks if the embed is empty. Empty embeds cannot be built. Returns:true if empty
length()
Returns the total character length of the embed. Returns: Total character countisValidLength()
Checks if the embed is within Discord’s length limits (6000 characters for bots). Returns:true if within limits
build()
Builds and returns the finalMessageEmbed. Validates all constraints.
Returns: The completed MessageEmbed
Throws:
IllegalStateExceptionif embed is empty, too long, or has too many fields (max 25)
Constants
ZERO_WIDTH_SPACE
A zero-width space character used for blank fields.Complete Example
Limits
- Title: 256 characters
- Description: 4096 characters
- Fields: Maximum 25 fields
- Field Name: 256 characters
- Field Value: 1024 characters
- Footer: 2048 characters
- Author: 256 characters
- Total Length: 6000 characters (for bots)
- URLs: 2048 characters