Class EmbedObject

java.lang.Object
me.croabeast.common.discord.EmbedObject

public class EmbedObject extends Object
Represents a Discord embed message.

The EmbedObject class provides a fluent API for building rich embed messages, including support for setting the title, description, URL, images, footer, color, and author. It also supports dynamic token replacement within the text fields.

Example usage:


 EmbedObject embed = new EmbedObject("{token}", "Hello, world!")
      .setTitle("My Plugin Title")
      .setDescription("This is a description with {token} replaced.")
      .setUrl("https://example.com")
      .setThumbnail("https://example.com/thumbnail.png")
      .setImage("https://example.com/image.png")
      .setFooter("Footer Text", "https://example.com/footer_icon.png")
      .setColor("#FFAA00")
      .setAuthor("Author Name", "https://example.com", "https://example.com/author_icon.png");

 // Add a field to the embed
 embed.addField("Field Name", "Field Value", true);
 

Since:
1.1
  • Constructor Details

    • EmbedObject

      public EmbedObject(String token, String message)
      Constructs a new EmbedObject with the specified token and message.
      Parameters:
      token - the token to be replaced in the embed text (must not be null)
      message - the message that replaces the token (must not be null)
  • Method Details

    • setTitle

      public EmbedObject setTitle(String text)
      Sets the title of the embed.
      Parameters:
      text - the title text
      Returns:
      this EmbedObject instance for chaining
    • setDescription

      public EmbedObject setDescription(String text)
      Sets the description of the embed.
      Parameters:
      text - the description text
      Returns:
      this EmbedObject instance for chaining
    • setUrl

      public EmbedObject setUrl(String text)
      Sets the URL of the embed.
      Parameters:
      text - the URL as a string
      Returns:
      this EmbedObject instance for chaining
    • setThumbnail

      public EmbedObject setThumbnail(String url)
      Sets the thumbnail URL for the embed.
      Parameters:
      url - the thumbnail URL
      Returns:
      this EmbedObject instance for chaining
    • setImage

      public EmbedObject setImage(String url)
      Sets the main image URL for the embed.
      Parameters:
      url - the image URL
      Returns:
      this EmbedObject instance for chaining
    • setFooter

      public EmbedObject setFooter(String text, String icon)
      Sets the footer text and icon for the embed.
      Parameters:
      text - the footer text
      icon - the footer icon URL
      Returns:
      this EmbedObject instance for chaining
    • setColor

      public EmbedObject setColor(String color)
      Sets the color of the embed.

      Attempts to decode the provided color string using Color.decode(String). If decoding fails, it attempts to retrieve a color by field name from Color.

      Parameters:
      color - the color string (e.g., "#FFAA00" or "RED")
      Returns:
      this EmbedObject instance for chaining
    • setAuthor

      public EmbedObject setAuthor(String name, String url, String icon)
      Sets the author information for the embed.
      Parameters:
      name - the author's name
      url - the author's URL
      icon - the author's icon URL
      Returns:
      this EmbedObject instance for chaining
    • addField

      public void addField(String name, String value, boolean inLine)
      Adds a field to the embed.
      Parameters:
      name - the name of the field
      value - the value of the field
      inLine - true if the field should be displayed inline; false otherwise