Class WebhookEmbedBuilder
- java.lang.Object
-
- club.minnced.discord.webhook.send.WebhookEmbedBuilder
-
public class WebhookEmbedBuilder extends Object
Builder for aWebhookEmbed
instance.
-
-
Constructor Summary
Constructors Constructor Description WebhookEmbedBuilder()
Creates an empty builderWebhookEmbedBuilder(@Nullable WebhookEmbed embed)
Creates a builder with predefined settings from the providedWebhookEmbed
instance
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description @NotNull WebhookEmbedBuilder
addField(WebhookEmbed.EmbedField field)
Adds anWebhookEmbed.EmbedField
to this embed.@NotNull WebhookEmbed
build()
Builds a newWebhookEmbed
instance from the current settings.static @NotNull WebhookEmbedBuilder
fromD4J(@NotNull discord4j.core.spec.EmbedCreateSpec spec)
Converts a Discord4JEmbedCreateSpec
into a compatible WebhookEmbedBuilder.static @NotNull WebhookEmbedBuilder
fromD4J(@NotNull discord4j.discordjson.json.EmbedData data)
Converts a Discord4JEmbedData
into a compatible WebhookEmbedBuilder.static @NotNull WebhookEmbedBuilder
fromD4J(@NotNull Consumer<? super discord4j.core.spec.EmbedCreateSpec> callback)
Deprecated.Replace withfromD4J(EmbedCreateSpec)
static @NotNull WebhookEmbedBuilder
fromJavacord(org.javacord.api.entity.message.embed.Embed embed)
Converts a JavacordEmbed
into a compatible WebhookEmbedBuilder.static @NotNull WebhookEmbedBuilder
fromJDA(net.dv8tion.jda.api.entities.MessageEmbed embed)
Converts a JDAMessageEmbed
into a compatible WebhookEmbedBuilder.boolean
isEmpty()
Whether this embed is currently empty.void
reset()
Resets the builder to its default state@NotNull WebhookEmbedBuilder
setAuthor(WebhookEmbed.EmbedAuthor author)
The author for this embed.@NotNull WebhookEmbedBuilder
setColor(@Nullable Integer color)
The rgb color to use for the line left to the resulting embed@NotNull WebhookEmbedBuilder
setDescription(@Nullable String description)
The description of the embed, this is the default text used in most embeds.@NotNull WebhookEmbedBuilder
setFooter(WebhookEmbed.EmbedFooter footer)
The footer for this embed.@NotNull WebhookEmbedBuilder
setImageUrl(@Nullable String imageUrl)
The image url for this embed.@NotNull WebhookEmbedBuilder
setThumbnailUrl(@Nullable String thumbnailUrl)
The thumbnail url for this embed.@NotNull WebhookEmbedBuilder
setTimestamp(@Nullable TemporalAccessor timestamp)
The timestamp for the resulting embed.@NotNull WebhookEmbedBuilder
setTitle(WebhookEmbed.EmbedTitle title)
The title for this embed.
-
-
-
Constructor Detail
-
WebhookEmbedBuilder
public WebhookEmbedBuilder()
Creates an empty builder
-
WebhookEmbedBuilder
public WebhookEmbedBuilder(@Nullable @Nullable WebhookEmbed embed)
Creates a builder with predefined settings from the providedWebhookEmbed
instance- Parameters:
embed
- The (nullable) embed to copy
-
-
Method Detail
-
reset
public void reset()
Resets the builder to its default state
-
setTimestamp
@NotNull public @NotNull WebhookEmbedBuilder setTimestamp(@Nullable @Nullable TemporalAccessor timestamp)
The timestamp for the resulting embed.
Usually used in combination withOffsetDateTime
.- Parameters:
timestamp
- The timestamp- Returns:
- The current builder for chaining convenience
- Throws:
DateTimeException
- If unable to convert to anOffsetDateTime
-
setColor
@NotNull public @NotNull WebhookEmbedBuilder setColor(@Nullable @Nullable Integer color)
The rgb color to use for the line left to the resulting embed- Parameters:
color
- The (nullable) color to use- Returns:
- The current builder for chaining convenience
-
setDescription
@NotNull public @NotNull WebhookEmbedBuilder setDescription(@Nullable @Nullable String description)
The description of the embed, this is the default text used in most embeds. It is displayed below author and title and above fields and image.- Parameters:
description
- The (nullable) description to use- Returns:
- The current builder for chaining convenience
-
setThumbnailUrl
@NotNull public @NotNull WebhookEmbedBuilder setThumbnailUrl(@Nullable @Nullable String thumbnailUrl)
The thumbnail url for this embed.
This is displayed as small image to the right side of the description.- Parameters:
thumbnailUrl
- The (nullable) thumbnail url- Returns:
- The current builder for chaining convenience
-
setImageUrl
@NotNull public @NotNull WebhookEmbedBuilder setImageUrl(@Nullable @Nullable String imageUrl)
The image url for this embed.
This is displayed below the description.- Parameters:
imageUrl
- The (nullable) image url- Returns:
- The current builder for chaining convenience
-
setFooter
@NotNull public @NotNull WebhookEmbedBuilder setFooter(@Nullable WebhookEmbed.EmbedFooter footer)
The footer for this embed.
This is displayed at the very bottom of the embed next to the timestamp.- Parameters:
footer
- The (nullable)WebhookEmbed.EmbedFooter
- Returns:
- The current builder for chaining convenience
-
setTitle
@NotNull public @NotNull WebhookEmbedBuilder setTitle(@Nullable WebhookEmbed.EmbedTitle title)
The title for this embed.
This is displayed below the author and above everything else.- Parameters:
title
- The (nullable)WebhookEmbed.EmbedTitle
- Returns:
- The current builder for chaining convenience
-
setAuthor
@NotNull public @NotNull WebhookEmbedBuilder setAuthor(@Nullable WebhookEmbed.EmbedAuthor author)
The author for this embed.
This is displayed above everything else in the embed.- Parameters:
author
- The (nullable)WebhookEmbed.EmbedAuthor
- Returns:
- The current builder for chaining convenience
-
addField
@NotNull public @NotNull WebhookEmbedBuilder addField(@NotNull WebhookEmbed.EmbedField field)
Adds anWebhookEmbed.EmbedField
to this embed.
And embed can hold up to 25 total fields. Each row can contain 2-3 fields depending on whether a thumbnail is configured.- Parameters:
field
- TheWebhookEmbed.EmbedField
to add- Returns:
- The current builder for chaining convenience
- Throws:
IllegalStateException
- If the maximum amount of fields has already been reached
-
isEmpty
public boolean isEmpty()
Whether this embed is currently empty.- Returns:
- True, if this embed is empty
-
build
@NotNull public @NotNull WebhookEmbed build()
Builds a newWebhookEmbed
instance from the current settings.- Returns:
- The
WebhookEmbed
- Throws:
IllegalStateException
- If this embed is currently empty
-
fromJDA
@NotNull public static @NotNull WebhookEmbedBuilder fromJDA(@NotNull net.dv8tion.jda.api.entities.MessageEmbed embed)
Converts a JDAMessageEmbed
into a compatible WebhookEmbedBuilder.- Parameters:
embed
- The embed- Returns:
- WebhookEmbedBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromJavacord
@NotNull public static @NotNull WebhookEmbedBuilder fromJavacord(@NotNull org.javacord.api.entity.message.embed.Embed embed)
Converts a JavacordEmbed
into a compatible WebhookEmbedBuilder.- Parameters:
embed
- The embed- Returns:
- WebhookEmbedBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull @Deprecated public static @NotNull WebhookEmbedBuilder fromD4J(@NotNull @NotNull Consumer<? super discord4j.core.spec.EmbedCreateSpec> callback)
Deprecated.Replace withfromD4J(EmbedCreateSpec)
Converts a Discord4JEmbedCreateSpec
into a compatible WebhookEmbedBuilder.- Parameters:
callback
- The callback which applies the desired settings to theEmbedCreateSpec
- Returns:
- WebhookEmbedBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull public static @NotNull WebhookEmbedBuilder fromD4J(@NotNull @NotNull discord4j.core.spec.EmbedCreateSpec spec)
Converts a Discord4JEmbedCreateSpec
into a compatible WebhookEmbedBuilder.- Parameters:
spec
- The embed create spec which applies the desired settings- Returns:
- WebhookEmbedBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull public static @NotNull WebhookEmbedBuilder fromD4J(@NotNull @NotNull discord4j.discordjson.json.EmbedData data)
Converts a Discord4JEmbedData
into a compatible WebhookEmbedBuilder.- Parameters:
data
- The embed data- Returns:
- WebhookEmbedBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
-