Class Embed

java.lang.Object
com.github.kaktushose.jda.commands.embeds.Embed

public class Embed extends Object
Builder for MessageEmbed that supports placeholders, localization and easier manipulation of MessageEmbed.Fields. Can also be loaded via EmbedDataSource.
  • Method Details

    • of

      public static Embed of(EmbedBuilder embedBuilder, String name, Map<String, @Nullable Object> placeholders, MessageResolver messageResolver)
      Constructs a new Embed.
      Parameters:
      embedBuilder - the EmbedBuilder to construct the Embed from
      name - the name of this embed used to identify it in EmbedDataSources
      placeholders - the global placeholders as defined in Embeds
    • of

      public static Embed of(DataObject object, String name, Map<String, @Nullable Object> placeholders, MessageResolver messageResolver)
      Constructs a new Embed.
      Parameters:
      object - the DataObject to construct the Embed from
      name - the name of this embed used to identify it in EmbedDataSources
      placeholders - the global placeholders as defined in Embeds
    • locale

      public Embed locale(Locale locale)
      Sets the Locale this Embed will be localized with.
      Parameters:
      locale - the Locale to use for localization
      Returns:
      this instance for fluent interface
      See Also:
    • name

      public String name()
      Gets the name of this embed. This isn't a field that get displayed but only the name this embed is referenced by in the EmbedDataSource.
      Returns:
      the name of this embed
    • title

      public Embed title(@Nullable String title)
      Sets the Title of the embed.
      Parameters:
      title - the title of the embed
      Returns:
      this instance for fluent interface
      See Also:
    • url

      public Embed url(@Nullable String url)

      Sets the URL of the embed.

      The Discord client mostly only uses this property in combination with the title for a clickable Hyperlink.

      If multiple embeds in a message use the same URL, the Discord client will merge them into a single embed and aggregate images into a gallery view.

      Returns:
      the builder after the URL has been set
      See Also:
    • title

      public Embed title(@Nullable String title, @Nullable String url)
      Sets the Title of the embed.
      Parameters:
      title - the title of the embed
      url - Makes the title into a hyperlink pointed at this url.
      Returns:
      this instance for fluent interface
      See Also:
    • description

      public Embed description(@Nullable CharSequence description)
      Sets the Description of the embed.
      Parameters:
      description - the description of the embed, null to reset
      Returns:
      this instance for fluent interface
      See Also:
    • color

      public Embed color(int color)
      Sets the Color of the embed.
      Parameters:
      color - The raw rgb value, or Role.DEFAULT_COLOR_RAW to use no color
      Returns:
      this instance for fluent interface
      See Also:
    • color

      public Embed color(@Nullable Color color)
      Sets the Color of the embed.
      Parameters:
      color - The Color of the embed or null to use no color
      Returns:
      this instance for fluent interface
      See Also:
    • timestamp

      public Embed timestamp(@Nullable TemporalAccessor accessor)
      Sets the Timestamp of the embed.
      Parameters:
      accessor - the temporal accessor of the timestamp
      Returns:
      this instance for fluent interface
      See Also:
    • footer

      public Embed footer(@Nullable String footer)
      Sets the Footer of the embed.
      Parameters:
      footer - the text of the footer of the embed. If this is not set or set to null, the footer will not appear in the embed.
      Returns:
      this instance for fluent interface
      See Also:
    • footer

      public Embed footer(@Nullable String footer, @Nullable String iconUrl)
      Sets the Footer of the embed.
      Parameters:
      footer - the text of the footer of the embed. If this is not set or set to null, the footer will not appear in the embed.
      iconUrl - the url of the icon for the footer
      Returns:
      this instance for fluent interface
      See Also:
    • thumbnail

      public Embed thumbnail(@Nullable String url)
      Sets the Thumbnail of the embed.
      Parameters:
      url - the url of the thumbnail of the embed
      Returns:
      this instance for fluent interface
      See Also:
    • image

      public Embed image(@Nullable String url)
      Sets the Image of the embed.
      Parameters:
      url - the url of the image of the embed
      Returns:
      this instance for fluent interface
      See Also:
    • author

      public Embed author(@Nullable String name)
      Sets the Author of the embed.
      Parameters:
      name - the name of the author of the embed. If this is not set, the author will not appear in the embed
      Returns:
      this instance for fluent interface
      See Also:
    • author

      public Embed author(@Nullable String name, @Nullable String url)
      Sets the Author of the embed.
      Parameters:
      name - the name of the author of the embed. If this is not set, the author will not appear in the embed
      url - the url of the author of the embed
      Returns:
      this instance for fluent interface
      See Also:
    • author

      public Embed author(@Nullable String name, @Nullable String url, @Nullable String iconUrl)
      Sets the Author of the embed.
      Parameters:
      name - the name of the author of the embed. If this is not set, the author will not appear in the embed
      url - the url of the author of the embed
      iconUrl - the url of the icon of the embed
      Returns:
      this instance for fluent interface
      See Also:
    • fields

      public Embed.Fields fields()
      Used to modify the fields of this embed.
      Returns:
      this instance for fluent interface
    • clear

      public Embed clear()

      Resets this builder to default state.

      All parts will be either empty or null after this method has returned.

      Returns:
      The current EmbedBuilder with default values
    • placeholders

      public Embed placeholders(Map<String, @Nullable Object> placeholders)

      Adds all the provided placeholders to this embed instance. The values will be replaced when build() is called.

      Existing entries with the same keys will be overwritten.

      Internally this uses the localization system, thus placeholders are limited by the used Localizer implementation

      Parameters:
      placeholders - a map of placeholder names to their corresponding values
      Returns:
      this instance for fluent interface
    • placeholders

      public Embed placeholders(Entry... placeholders)

      Adds all the provided placeholders to this embed instance. The values will be replaced when build() is called.

      Existing entries with the same keys will be overwritten.

      Internally this uses the localization system, thus placeholders are limited by the used Localizer implementation

      Parameters:
      placeholders - the entries to add
      Returns:
      this instance for fluent interface
    • build

      public MessageEmbed build()
      Returns a MessageEmbed just like EmbedBuilder.build(), but will also localize this embed based on the locale(Locale) and placeholders provided.
      Returns:
      the built, sendable MessageEmbed
    • toMessageCreateData

      public MessageCreateData toMessageCreateData()
      Transforms this embed into MessageCreateData.
      Returns:
      the transformed MessageCreateData
    • toMessageEditData

      public MessageEditData toMessageEditData()
      Transforms this embed into MessageEditData.
      Returns:
      the transformed MessageEditData