Package net.dv8tion.jda.webhook
Class WebhookMessageBuilder
- java.lang.Object
-
- net.dv8tion.jda.webhook.WebhookMessageBuilder
-
public class WebhookMessageBuilder extends java.lang.Object
Builder for aWebhookMessage
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_FILES
The maximum amount of files that can be added to a message (10)
-
Constructor Summary
Constructors Constructor Description WebhookMessageBuilder()
Creates a new empty WebhookMessageBuilderWebhookMessageBuilder(Message message)
Creates a new WebhookMessageBuilder and applies the information of the providedMessage
as preset values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebhookMessageBuilder
addEmbeds(java.util.Collection<MessageEmbed> embeds)
Adds the providedMessageEmbeds
to this builder.WebhookMessageBuilder
addEmbeds(MessageEmbed... embeds)
Adds the providedMessageEmbeds
to this builder.WebhookMessageBuilder
addFile(java.io.File file)
Adds the provided file to the resulting message.WebhookMessageBuilder
addFile(java.lang.String name, byte[] data)
Adds the provided file to the resulting message.WebhookMessageBuilder
addFile(java.lang.String name, java.io.File file)
Adds the provided file to the resulting message.WebhookMessageBuilder
addFile(java.lang.String name, java.io.InputStream data)
Adds the provided file to the resulting message.WebhookMessageBuilder
append(java.lang.String content)
Appends to the currently set content of the resulting message.WebhookMessage
build()
Builds aWebhookMessage
instance with the current state of this builder.int
getFileAmount()
The amount of files added to this WebhookMessageBuilder instanceboolean
isEmpty()
Whether this WebhookMessageBuilder contains any readable content.WebhookMessageBuilder
reset()
Resets this builder to default settings.WebhookMessageBuilder
resetEmbeds()
Removes all embeds from this builder.WebhookMessageBuilder
resetFiles()
Removes all added resources.WebhookMessageBuilder
setAvatarUrl(java.lang.String avatarUrl)
Sets the avatar url that should be used for the resulting message.WebhookMessageBuilder
setContent(java.lang.String content)
Sets the content of the resulting message.WebhookMessageBuilder
setTTS(boolean tts)
Sets whether the resulting message should use Text-To-Speech.WebhookMessageBuilder
setUsername(java.lang.String username)
Sets the username that should be used for the resulting message.
-
-
-
Field Detail
-
MAX_FILES
public static final int MAX_FILES
The maximum amount of files that can be added to a message (10)- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WebhookMessageBuilder
public WebhookMessageBuilder(Message message)
Creates a new WebhookMessageBuilder and applies the information of the providedMessage
as preset values.
This will not copy any attachments!- Parameters:
message
- TheMessage
used to set initial values of the builder
-
WebhookMessageBuilder
public WebhookMessageBuilder()
Creates a new empty WebhookMessageBuilder
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Whether this WebhookMessageBuilder contains any readable content.
When the builder is empty it cannot successfully build aWebhookMessage
.- Returns:
- True, if this builder has no readable content
-
getFileAmount
public int getFileAmount()
The amount of files added to this WebhookMessageBuilder instance- Returns:
- Amount of added files
-
reset
public WebhookMessageBuilder reset()
Resets this builder to default settings.- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
resetFiles
public WebhookMessageBuilder resetFiles()
Removes all added resources. ThegetFileAmount()
will report0
after this happened, however the allocated array will remain.- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
resetEmbeds
public WebhookMessageBuilder resetEmbeds()
Removes all embeds from this builder.- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
addEmbeds
public WebhookMessageBuilder addEmbeds(MessageEmbed... embeds)
Adds the providedMessageEmbeds
to this builder.You can send up to 10 embeds per message! If more are sent they will not be displayed.
- Parameters:
embeds
- The embeds to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If any of the provided embeds isnull
or exceeds the maximum total character count ofMessageEmbed.EMBED_MAX_LENGTH_BOT
-
addEmbeds
public WebhookMessageBuilder addEmbeds(java.util.Collection<MessageEmbed> embeds)
Adds the providedMessageEmbeds
to this builder.You can send up to 10 embeds per message! If more are sent they will not be displayed.
- Parameters:
embeds
- The embeds to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If any of the provided embeds isnull
or exceeds the maximum total character count ofMessageEmbed.EMBED_MAX_LENGTH_BOT
-
setContent
public WebhookMessageBuilder setContent(java.lang.String content)
Sets the content of the resulting message.
This will override the previous content.- Parameters:
content
- The new content- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided content exceeds2000
characters in length
-
append
public WebhookMessageBuilder append(java.lang.String content)
Appends to the currently set content of the resulting message.- Parameters:
content
- The content to append- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided content isnull
or the resulting content would exceed2000
characters in length
-
setUsername
public WebhookMessageBuilder setUsername(java.lang.String username)
Sets the username that should be used for the resulting message.
This will override the default username of the webhook.- Parameters:
username
- The username to use for this message- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
setAvatarUrl
public WebhookMessageBuilder setAvatarUrl(java.lang.String avatarUrl)
Sets the avatar url that should be used for the resulting message.
This will override the default avatar of the webhook.- Parameters:
avatarUrl
- The avatar url to use for this message- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
addFile
public WebhookMessageBuilder addFile(java.io.File file)
Adds the provided file to the resulting message.
Shortcut foraddFile(String, File)
.- Parameters:
file
- The file to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided file is null, does not exist, or is not readablejava.lang.IllegalStateException
- If the file limit has already been reached- See Also:
resetFiles()
-
addFile
public WebhookMessageBuilder addFile(java.lang.String name, java.io.File file)
Adds the provided file to the resulting message.- Parameters:
name
- The name to use for this filefile
- The file to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided file is null, does not exist, or is not readablejava.lang.IllegalStateException
- If the file limit has already been reached- See Also:
resetFiles()
-
addFile
public WebhookMessageBuilder addFile(java.lang.String name, byte[] data)
Adds the provided file to the resulting message.- Parameters:
name
- The name to use for this filedata
- The file data to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided name data is nulljava.lang.IllegalStateException
- If the file limit has already been reached- See Also:
resetFiles()
-
addFile
public WebhookMessageBuilder addFile(java.lang.String name, java.io.InputStream data)
Adds the provided file to the resulting message.- Parameters:
name
- The name to use for this filedata
- The file data to add- Returns:
- The current WebhookMessageBuilder for chaining convenience
- Throws:
java.lang.IllegalArgumentException
- If the provided name or data is nulljava.lang.IllegalStateException
- If the file limit has already been reached- See Also:
resetFiles()
-
setTTS
public WebhookMessageBuilder setTTS(boolean tts)
Sets whether the resulting message should use Text-To-Speech.- Parameters:
tts
- True, if the resulting message should use Text-To-Speech- Returns:
- The current WebhookMessageBuilder for chaining convenience
-
build
public WebhookMessage build()
Builds aWebhookMessage
instance with the current state of this builder.- Returns:
- The resulting
WebhookMessage
- Throws:
java.lang.IllegalStateException
- If this builder is empty
-
-