public class EmbedBuilder
extends java.lang.Object
MessageEmbeds
.
Modifier and Type | Field | Description |
---|---|---|
static java.util.regex.Pattern |
URL_PATTERN |
|
static java.lang.String |
ZERO_WIDTH_SPACE |
Constructor | Description |
---|---|
EmbedBuilder() |
Creates an EmbedBuilder to be used to creates an embed to send.
|
EmbedBuilder(EmbedBuilder builder) |
|
EmbedBuilder(MessageEmbed embed) |
Creates an EmbedBuilder using fields in an existing embed.
|
Modifier and Type | Method | Description |
---|---|---|
EmbedBuilder |
addBlankField(boolean inline) |
Adds a blank (empty) Field to the embed.
|
EmbedBuilder |
addField(java.lang.String name,
java.lang.String value,
boolean inline) |
Adds a Field to the embed.
|
EmbedBuilder |
addField(MessageEmbed.Field field) |
Copies the provided Field into a new Field for this builder.
|
EmbedBuilder |
appendDescription(java.lang.CharSequence description) |
Appends to the description of the embed.
|
MessageEmbed |
build() |
Returns a
MessageEmbed
that has been checked as being valid for sending. |
EmbedBuilder |
clear() |
Resets this builder to default state.
|
EmbedBuilder |
clearFields() |
Clears all fields from the embed, such as those created with the
EmbedBuilder(MessageEmbed)
constructor or via the
addField methods. |
java.lang.StringBuilder |
getDescriptionBuilder() |
The
StringBuilder used to
build the description for the embed. |
java.util.List<MessageEmbed.Field> |
getFields() |
Modifiable list of
MessageEmbed Fields that the builder will
use for build() . |
boolean |
isEmpty() |
Checks if the given embed is empty.
|
boolean |
isValidLength(AccountType type) |
Checks whether the constructed
MessageEmbed
is within the limits for the specified AccountType
Bot: 6000
Client: 2000
|
int |
length() |
The overall length of the current EmbedBuilder in displayed characters.
|
EmbedBuilder |
setAuthor(java.lang.String name) |
Sets the Author of the embed.
|
EmbedBuilder |
setAuthor(java.lang.String name,
java.lang.String url) |
Sets the Author of the embed.
|
EmbedBuilder |
setAuthor(java.lang.String name,
java.lang.String url,
java.lang.String iconUrl) |
Sets the Author of the embed.
|
EmbedBuilder |
setColor(int color) |
Sets the raw RGB color value for the embed.
|
EmbedBuilder |
setColor(java.awt.Color color) |
Sets the Color of the embed.
|
EmbedBuilder |
setDescription(java.lang.CharSequence description) |
Sets the Description of the embed.
|
EmbedBuilder |
setFooter(java.lang.String text,
java.lang.String iconUrl) |
Sets the Footer of the embed.
|
EmbedBuilder |
setImage(java.lang.String url) |
Sets the Image of the embed.
|
EmbedBuilder |
setThumbnail(java.lang.String url) |
Sets the Thumbnail of the embed.
|
EmbedBuilder |
setTimestamp(java.time.temporal.TemporalAccessor temporal) |
Sets the Timestamp of the embed.
|
EmbedBuilder |
setTitle(java.lang.String title) |
Sets the Title of the embed.
|
EmbedBuilder |
setTitle(java.lang.String title,
java.lang.String url) |
Sets the Title of the embed.
|
public static final java.lang.String ZERO_WIDTH_SPACE
public static final java.util.regex.Pattern URL_PATTERN
public EmbedBuilder()
null
to the setter method.public EmbedBuilder(EmbedBuilder builder)
public EmbedBuilder(MessageEmbed embed)
embed
- the existing embedpublic MessageEmbed build()
MessageEmbed
that has been checked as being valid for sending.MessageEmbed
java.lang.IllegalStateException
- If the embed is empty. Can be checked with isEmpty()
.public EmbedBuilder clear()
public boolean isEmpty()
public int length()
MessageEmbed.getLength()
value.public boolean isValidLength(AccountType type)
MessageEmbed
is within the limits for the specified AccountType
type
- The AccountType
to validatelength
is less or equal to the specific limitjava.lang.IllegalArgumentException
- If provided with null
public EmbedBuilder setTitle(java.lang.String title)
title
- the title of the embedjava.lang.IllegalArgumentException
- title
is an empty String.title
is greater than MessageEmbed.TITLE_MAX_LENGTH
.public EmbedBuilder setTitle(java.lang.String title, java.lang.String url)
title
- the title of the embedurl
- Makes the title into a hyperlink pointed at this url.java.lang.IllegalArgumentException
- title
is an empty String.title
is greater than MessageEmbed.TITLE_MAX_LENGTH
.url
is longer than MessageEmbed.URL_MAX_LENGTH
.url
is not a properly formatted http or https url.public java.lang.StringBuilder getDescriptionBuilder()
StringBuilder
used to
build the description for the embed.
setDescription(null)
public final EmbedBuilder setDescription(java.lang.CharSequence description)
description
- the description of the embed, null
to resetjava.lang.IllegalArgumentException
- If the length of description
is greater than MessageEmbed.TEXT_MAX_LENGTH
public EmbedBuilder appendDescription(java.lang.CharSequence description)
description
- the string to append to the description of the embedjava.lang.IllegalArgumentException
- description
String is nulldescription
is greater than MessageEmbed.TEXT_MAX_LENGTH
.public EmbedBuilder setTimestamp(java.time.temporal.TemporalAccessor temporal)
Hint: You can get the current time using Instant.now()
or convert time from a
millisecond representation by using Instant.ofEpochMilli(long)
;
temporal
- the temporal accessor of the timestamppublic EmbedBuilder setColor(java.awt.Color color)
color
- The Color
of the embed
or null
to use no colorsetColor(int)
public EmbedBuilder setColor(int color)
color
- The raw rgb value, or Role.DEFAULT_COLOR_RAW
to use no colorsetColor(java.awt.Color)
public EmbedBuilder setThumbnail(java.lang.String url)
Uploading images with Embeds
When uploading an image
(using MessageChannel.sendFile(...)
)
you can reference said image using the specified filename as URI attachment://filename.ext
.
Example
MessageChannel channel; // = reference of a MessageChannel
MessageBuilder message = new MessageBuilder();
EmbedBuilder embed = new EmbedBuilder();
InputStream file = new URL("https://http.cat/500").openStream();
embed.setThumbnail("attachment://cat.png") // we specify this in sendFile as "cat.png"
.setDescription("This is a cute cat :3");
message.setEmbed(embed.build());
channel.sendFile(file, "cat.png", message.build()).queue();
url
- the url of the thumbnail of the embedjava.lang.IllegalArgumentException
- url
is longer than MessageEmbed.URL_MAX_LENGTH
.url
is not a properly formatted http or https url.public EmbedBuilder setImage(java.lang.String url)
Uploading images with Embeds
When uploading an image
(using MessageChannel.sendFile(...)
)
you can reference said image using the specified filename as URI attachment://filename.ext
.
Example
MessageChannel channel; // = reference of a MessageChannel
MessageBuilder message = new MessageBuilder();
EmbedBuilder embed = new EmbedBuilder();
InputStream file = new URL("https://http.cat/500").openStream();
embed.setImage("attachment://cat.png") // we specify this in sendFile as "cat.png"
.setDescription("This is a cute cat :3");
message.setEmbed(embed.build());
channel.sendFile(file, "cat.png", message.build()).queue();
url
- the url of the image of the embedjava.lang.IllegalArgumentException
- url
is longer than MessageEmbed.URL_MAX_LENGTH
.url
is not a properly formatted http or https url.MessageChannel.sendFile(...)
public EmbedBuilder setAuthor(java.lang.String name)
name
- the name of the author of the embed. If this is not set, the author will not appear in the embedpublic EmbedBuilder setAuthor(java.lang.String name, java.lang.String url)
name
- the name of the author of the embed. If this is not set, the author will not appear in the embedurl
- the url of the author of the embedjava.lang.IllegalArgumentException
- url
is longer than MessageEmbed.URL_MAX_LENGTH
.url
is not a properly formatted http or https url.public EmbedBuilder setAuthor(java.lang.String name, java.lang.String url, java.lang.String iconUrl)
Uploading images with Embeds
When uploading an image
(using MessageChannel.sendFile(...)
)
you can reference said image using the specified filename as URI attachment://filename.ext
.
Example
MessageChannel channel; // = reference of a MessageChannel
MessageBuilder message = new MessageBuilder();
EmbedBuilder embed = new EmbedBuilder();
InputStream file = new URL("https://http.cat/500").openStream();
embed.setAuthor("Minn", null, "attachment://cat.png") // we specify this in sendFile as "cat.png"
.setDescription("This is a cute cat :3");
message.setEmbed(embed.build());
channel.sendFile(file, "cat.png", message.build()).queue();
name
- the name of the author of the embed. If this is not set, the author will not appear in the embedurl
- the url of the author of the embediconUrl
- the url of the icon for the authorjava.lang.IllegalArgumentException
- url
is longer than MessageEmbed.URL_MAX_LENGTH
.url
is not a properly formatted http or https url.iconUrl
is longer than MessageEmbed.URL_MAX_LENGTH
.iconUrl
is not a properly formatted http or https url.public EmbedBuilder setFooter(java.lang.String text, java.lang.String iconUrl)
Uploading images with Embeds
When uploading an image
(using MessageChannel.sendFile(...)
)
you can reference said image using the specified filename as URI attachment://filename.ext
.
Example
MessageChannel channel; // = reference of a MessageChannel
MessageBuilder message = new MessageBuilder();
EmbedBuilder embed = new EmbedBuilder();
InputStream file = new URL("https://http.cat/500").openStream();
embed.setFooter("Cool footer!", "attachment://cat.png") // we specify this in sendFile as "cat.png"
.setDescription("This is a cute cat :3");
message.setEmbed(embed.build());
channel.sendFile(file, "cat.png", message.build()).queue();
text
- the text of the footer of the embed. If this is not set, the footer will not appear in the embed.iconUrl
- the url of the icon for the footerjava.lang.IllegalArgumentException
- text
is longer than MessageEmbed.TEXT_MAX_LENGTH
.iconUrl
is longer than MessageEmbed.URL_MAX_LENGTH
.iconUrl
is not a properly formatted http or https url.public EmbedBuilder addField(MessageEmbed.Field field)
addField(String, String, boolean)
field
- the field object to addpublic EmbedBuilder addField(java.lang.String name, java.lang.String value, boolean inline)
Note: If a blank string is provided to either name
or value
, the blank string is replaced
with ZERO_WIDTH_SPACE
.
name
- the name of the Field, displayed in bold above the value
.value
- the contents of the field.inline
- whether or not this field should display inline.java.lang.IllegalArgumentException
- name
or value
is set. Both must be set.name
is greater than MessageEmbed.TITLE_MAX_LENGTH
.value
is greater than MessageEmbed.VALUE_MAX_LENGTH
.public EmbedBuilder addBlankField(boolean inline)
inline
- whether or not this field should display inlinepublic EmbedBuilder clearFields()
EmbedBuilder(MessageEmbed)
constructor or via the
addField
methods.public java.util.List<MessageEmbed.Field> getFields()
MessageEmbed
Fields that the builder will
use for build()
.
List
and it will then be applied in the
built MessageEmbed. These fields will be available again through MessageEmbed.getFields()
.Fields