Package org.javacord.api.entity.message
Class WebhookMessageBuilder
- java.lang.Object
-
- org.javacord.api.entity.message.WebhookMessageBuilder
-
public class WebhookMessageBuilder extends Object
This class can help you to create webhook messages.
-
-
Field Summary
Fields Modifier and Type Field Description protected WebhookMessageBuilderDelegatedelegateThe message delegate used by this instance.
-
Constructor Summary
Constructors Constructor Description WebhookMessageBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description WebhookMessageBuilderaddAttachment(byte[] bytes, String fileName)Adds an attachment to the message.WebhookMessageBuilderaddAttachment(BufferedImage image, String fileName)Adds an attachment to the message.WebhookMessageBuilderaddAttachment(File file)Adds an attachment to the message.WebhookMessageBuilderaddAttachment(InputStream stream, String fileName)Adds an attachment to the message.WebhookMessageBuilderaddAttachment(URL url)Adds an attachment to the message.WebhookMessageBuilderaddAttachment(Icon icon)Adds an attachment to the message.WebhookMessageBuilderaddAttachmentAsSpoiler(byte[] bytes, String fileName)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddAttachmentAsSpoiler(BufferedImage image, String fileName)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddAttachmentAsSpoiler(File file)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddAttachmentAsSpoiler(InputStream stream, String fileName)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddAttachmentAsSpoiler(URL url)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddAttachmentAsSpoiler(Icon icon)Adds an attachment to the message and marks it as spoiler.WebhookMessageBuilderaddEmbed(EmbedBuilder embed)Adds the embed to the message.WebhookMessageBuilderaddEmbeds(EmbedBuilder... embeds)Adds the embeds to the message.WebhookMessageBuilderaddFile(byte[] bytes, String fileName)Adds a file to the message.WebhookMessageBuilderaddFile(BufferedImage image, String fileName)Adds a file to the message.WebhookMessageBuilderaddFile(File file)Adds a file to the message.WebhookMessageBuilderaddFile(InputStream stream, String fileName)Adds a file to the message.WebhookMessageBuilderaddFile(URL url)Adds a file to the message and marks it as a spoiler.WebhookMessageBuilderaddFile(Icon icon)Adds a file to the message.WebhookMessageBuilderaddFileAsSpoiler(byte[] bytes, String fileName)Adds a file to the message and marks it as spoiler.WebhookMessageBuilderaddFileAsSpoiler(BufferedImage image, String fileName)Adds a file to the message and marks it as spoiler.WebhookMessageBuilderaddFileAsSpoiler(File file)Adds a file to the message and marks it as spoiler.WebhookMessageBuilderaddFileAsSpoiler(InputStream stream, String fileName)Adds a file to the message and marks it as spoiler.WebhookMessageBuilderaddFileAsSpoiler(URL url)Adds a file to the message and marks it as a spoiler.WebhookMessageBuilderaddFileAsSpoiler(Icon icon)Adds a file to the message and marks it as spoiler.WebhookMessageBuilderappend(Object object)Appends the string representation of the object (callingString.valueOf(Object)method) to the message.WebhookMessageBuilderappend(String message, MessageDecoration... decorations)Appends a sting with or without decoration to the message.WebhookMessageBuilderappend(Mentionable entity)Appends a mentionable entity (usually a user or channel) to the message.WebhookMessageBuilderappendCode(String language, String code)Appends code to the message.WebhookMessageBuilderappendNewLine()Appends a new line to the message.static WebhookMessageBuilderfromMessage(Message message)Creates a webhook message builder from a message.StringBuildergetStringBuilder()Gets theStringBuilderwhich is used to build the message.WebhookMessageBuilderremoveAllEmbeds()Removes all embeds from the message.WebhookMessageBuilderremoveEmbed(EmbedBuilder embed)Removes the embed from the message.WebhookMessageBuilderremoveEmbeds(EmbedBuilder... embeds)Removes the embeds from the message.CompletableFuture<Message>send(DiscordApi api, long webhookId, String webhookToken)Sends the message.CompletableFuture<Message>send(DiscordApi api, String webhookUrl)Sends the message.CompletableFuture<Message>send(DiscordApi api, String webhookId, String webhookToken)Sends the message.CompletableFuture<Message>send(IncomingWebhook webhook)Sends the message.CompletableFuture<Void>sendSilently(DiscordApi api, long webhookId, String webhookToken)Sends the message without waiting for a response.CompletableFuture<Void>sendSilently(DiscordApi api, String webhookUrl)Sends the message without waiting for a response.CompletableFuture<Void>sendSilently(DiscordApi api, String webhookId, String webhookToken)Sends the message without waiting for a response.CompletableFuture<Void>sendSilently(IncomingWebhook webhook)Sends the message without waiting for a response.WebhookMessageBuildersetAllowedMentions(AllowedMentions allowedMentions)Controls who will be mentioned if mentions exist in the message.WebhookMessageBuildersetContent(String content)Sets the content of the message.WebhookMessageBuildersetDisplayAuthor(MessageAuthor author)Sets the display avatar of the webhook.WebhookMessageBuildersetDisplayAuthor(User author)Sets the display avatar of the webhook.WebhookMessageBuildersetDisplayAvatar(URL avatarUrl)Sets the display avatar of the webhook.WebhookMessageBuildersetDisplayAvatar(Icon avatar)Sets the display avatar of the webhook.WebhookMessageBuildersetDisplayName(String displayName)Sets the display name of the webhook.WebhookMessageBuildersetTts(boolean tts)Sets if the message should be text to speech.
-
-
-
Field Detail
-
delegate
protected final WebhookMessageBuilderDelegate delegate
The message delegate used by this instance.
-
-
Method Detail
-
fromMessage
public static WebhookMessageBuilder fromMessage(Message message)
Creates a webhook message builder from a message.- Parameters:
message- The message to copy.- Returns:
- A webhook message builder which would produce the same text as the given message.
-
appendCode
public WebhookMessageBuilder appendCode(String language, String code)
Appends code to the message.- Parameters:
language- The language, e.g. "java".code- The code.- Returns:
- The current instance in order to chain call methods.
-
append
public WebhookMessageBuilder append(String message, MessageDecoration... decorations)
Appends a sting with or without decoration to the message.- Parameters:
message- The string to append.decorations- The decorations of the string.- Returns:
- The current instance in order to chain call methods.
-
append
public WebhookMessageBuilder append(Mentionable entity)
Appends a mentionable entity (usually a user or channel) to the message.- Parameters:
entity- The entity to mention.- Returns:
- The current instance in order to chain call methods.
-
append
public WebhookMessageBuilder append(Object object)
Appends the string representation of the object (callingString.valueOf(Object)method) to the message.- Parameters:
object- The object to append.- Returns:
- The current instance in order to chain call methods.
- See Also:
StringBuilder.append(Object)
-
appendNewLine
public WebhookMessageBuilder appendNewLine()
Appends a new line to the message.- Returns:
- The current instance in order to chain call methods.
-
setContent
public WebhookMessageBuilder setContent(String content)
Sets the content of the message. This method overwrites all previous content changes (usingappend(String, MessageDecoration...)for example).- Parameters:
content- The new content of the message.- Returns:
- The current instance in order to chain call methods.
-
addEmbed
public WebhookMessageBuilder addEmbed(EmbedBuilder embed)
Adds the embed to the message.- Parameters:
embed- The embed to add.- Returns:
- The current instance in order to chain call methods.
-
addEmbeds
public WebhookMessageBuilder addEmbeds(EmbedBuilder... embeds)
Adds the embeds to the message.- Parameters:
embeds- The embeds to add.- Returns:
- The current instance in order to chain call methods.
-
removeEmbed
public WebhookMessageBuilder removeEmbed(EmbedBuilder embed)
Removes the embed from the message.- Parameters:
embed- The embed to remove.- Returns:
- The current instance in order to chain call methods.
-
removeEmbeds
public WebhookMessageBuilder removeEmbeds(EmbedBuilder... embeds)
Removes the embeds from the message.- Parameters:
embeds- The embeds to remove.- Returns:
- The current instance in order to chain call methods.
-
removeAllEmbeds
public WebhookMessageBuilder removeAllEmbeds()
Removes all embeds from the message.- Returns:
- The current instance in order to chain call methods.
-
setTts
public WebhookMessageBuilder setTts(boolean tts)
Sets if the message should be text to speech.- Parameters:
tts- Whether the message should be text to speech or not.- Returns:
- The current instance in order to chain call methods.
-
addFile
public WebhookMessageBuilder addFile(BufferedImage image, String fileName)
Adds a file to the message.- Parameters:
image- The image to add as an attachment.fileName- The file name of the image.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(BufferedImage, String)
-
addFile
public WebhookMessageBuilder addFile(File file)
Adds a file to the message.- Parameters:
file- The file to add as an attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(File)
-
addFile
public WebhookMessageBuilder addFile(Icon icon)
Adds a file to the message.- Parameters:
icon- The icon to add as an attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(Icon)
-
addFile
public WebhookMessageBuilder addFile(URL url)
Adds a file to the message and marks it as a spoiler.- Parameters:
url- The url of the attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(URL)
-
addFile
public WebhookMessageBuilder addFile(byte[] bytes, String fileName)
Adds a file to the message.- Parameters:
bytes- The bytes of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(byte[], String)
-
addFile
public WebhookMessageBuilder addFile(InputStream stream, String fileName)
Adds a file to the message.- Parameters:
stream- The stream of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(InputStream, String)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(BufferedImage image, String fileName)
Adds a file to the message and marks it as spoiler.- Parameters:
image- The image to add as an attachment.fileName- The file name of the image.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachmentAsSpoiler(BufferedImage, String)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(File file)
Adds a file to the message and marks it as spoiler.- Parameters:
file- The file to add as an attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachmentAsSpoiler(File)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(Icon icon)
Adds a file to the message and marks it as spoiler.- Parameters:
icon- The icon to add as an attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachmentAsSpoiler(Icon)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(URL url)
Adds a file to the message and marks it as a spoiler.- Parameters:
url- The url of the attachment.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(URL)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(byte[] bytes, String fileName)
Adds a file to the message and marks it as spoiler.- Parameters:
bytes- The bytes of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachmentAsSpoiler(byte[], String)
-
addFileAsSpoiler
public WebhookMessageBuilder addFileAsSpoiler(InputStream stream, String fileName)
Adds a file to the message and marks it as spoiler.- Parameters:
stream- The stream of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
- See Also:
addAttachment(InputStream, String)
-
addAttachment
public WebhookMessageBuilder addAttachment(BufferedImage image, String fileName)
Adds an attachment to the message.- Parameters:
image- The image to add as an attachment.fileName- The file name of the image.- Returns:
- The current instance in order to chain call methods.
-
addAttachment
public WebhookMessageBuilder addAttachment(File file)
Adds an attachment to the message.- Parameters:
file- The file to add as an attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachment
public WebhookMessageBuilder addAttachment(Icon icon)
Adds an attachment to the message.- Parameters:
icon- The icon to add as an attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachment
public WebhookMessageBuilder addAttachment(URL url)
Adds an attachment to the message.- Parameters:
url- The url of the attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachment
public WebhookMessageBuilder addAttachment(byte[] bytes, String fileName)
Adds an attachment to the message.- Parameters:
bytes- The bytes of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
-
addAttachment
public WebhookMessageBuilder addAttachment(InputStream stream, String fileName)
Adds an attachment to the message.- Parameters:
stream- The stream of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(BufferedImage image, String fileName)
Adds an attachment to the message and marks it as spoiler.- Parameters:
image- The image to add as an attachment.fileName- The file name of the image.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(File file)
Adds an attachment to the message and marks it as spoiler.- Parameters:
file- The file to add as an attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(Icon icon)
Adds an attachment to the message and marks it as spoiler.- Parameters:
icon- The icon to add as an attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(URL url)
Adds an attachment to the message and marks it as spoiler.- Parameters:
url- The url of the attachment.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(byte[] bytes, String fileName)
Adds an attachment to the message and marks it as spoiler.- Parameters:
bytes- The bytes of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
-
addAttachmentAsSpoiler
public WebhookMessageBuilder addAttachmentAsSpoiler(InputStream stream, String fileName)
Adds an attachment to the message and marks it as spoiler.- Parameters:
stream- The stream of the file.fileName- The name of the file.- Returns:
- The current instance in order to chain call methods.
-
setAllowedMentions
public WebhookMessageBuilder setAllowedMentions(AllowedMentions allowedMentions)
Controls who will be mentioned if mentions exist in the message.- Parameters:
allowedMentions- The mention object.- Returns:
- The current instance in order to chain call methods.
-
setDisplayName
public WebhookMessageBuilder setDisplayName(String displayName)
Sets the display name of the webhook.- Parameters:
displayName- The display name of the webhook.- Returns:
- The current instance in order to chain call methods.
-
setDisplayAvatar
public WebhookMessageBuilder setDisplayAvatar(URL avatarUrl)
Sets the display avatar of the webhook.- Parameters:
avatarUrl- The display avatar of the webhook.- Returns:
- The current instance in order to chain call methods.
-
setDisplayAvatar
public WebhookMessageBuilder setDisplayAvatar(Icon avatar)
Sets the display avatar of the webhook.- Parameters:
avatar- The display avatar of the webhook.- Returns:
- The current instance in order to chain call methods.
-
setDisplayAuthor
public WebhookMessageBuilder setDisplayAuthor(MessageAuthor author)
Sets the display avatar of the webhook.- Parameters:
author- The author to take display name and display avatar of.- Returns:
- The current instance in order to chain call methods.
-
setDisplayAuthor
public WebhookMessageBuilder setDisplayAuthor(User author)
Sets the display avatar of the webhook.- Parameters:
author- The author to take display name and display avatar of.- Returns:
- The current instance in order to chain call methods.
-
getStringBuilder
public StringBuilder getStringBuilder()
Gets theStringBuilderwhich is used to build the message.- Returns:
- The StringBuilder which is used to build the message.
-
send
public CompletableFuture<Message> send(IncomingWebhook webhook)
Sends the message.- Parameters:
webhook- The webhook from which the message should be sent.- Returns:
- The sent message.
-
send
public CompletableFuture<Message> send(DiscordApi api, long webhookId, String webhookToken)
Sends the message.- Parameters:
api- The api instance needed to send and return the message.webhookId- The id of the webhook from which the message should be sent.webhookToken- The token of the webhook from which the message should be sent.- Returns:
- The sent message.
-
send
public CompletableFuture<Message> send(DiscordApi api, String webhookId, String webhookToken)
Sends the message.- Parameters:
api- The api instance needed to send and return the message.webhookId- The id of the webhook from which the message should be sent.webhookToken- The token of the webhook from which the message should be sent.- Returns:
- The sent message.
-
send
public CompletableFuture<Message> send(DiscordApi api, String webhookUrl) throws IllegalArgumentException
Sends the message.- Parameters:
api- The api instance needed to send the message.webhookUrl- The url of the webhook from which the message should be sent.- Returns:
- The sent message.
- Throws:
IllegalArgumentException- If the link isn't valid.
-
sendSilently
public CompletableFuture<Void> sendSilently(IncomingWebhook webhook)
Sends the message without waiting for a response.- Parameters:
webhook- The webhook from which the message should be sent.- Returns:
- A CompletableFuture indicating whether or not sending the request to discord was successful.
-
sendSilently
public CompletableFuture<Void> sendSilently(DiscordApi api, long webhookId, String webhookToken)
Sends the message without waiting for a response.- Parameters:
api- The api instance needed to send the message.webhookId- The id of the webhook from which the message should be sent.webhookToken- The token of the webhook from which the message should be sent.- Returns:
- A CompletableFuture indicating whether or not sending the request to discord was successful.
-
sendSilently
public CompletableFuture<Void> sendSilently(DiscordApi api, String webhookId, String webhookToken)
Sends the message without waiting for a response.- Parameters:
api- The api instance needed to send the message.webhookId- The id of the webhook from which the message should be sent.webhookToken- The token of the webhook from which the message should be sent.- Returns:
- A CompletableFuture indicating whether or not sending the request to discord was successful.
-
sendSilently
public CompletableFuture<Void> sendSilently(DiscordApi api, String webhookUrl) throws IllegalArgumentException
Sends the message without waiting for a response.- Parameters:
api- The api instance needed to send the message.webhookUrl- The url of the webhook from which the message should be sent.- Returns:
- A CompletableFuture indicating whether or not sending the request to discord was successful.
- Throws:
IllegalArgumentException- If the link isn't valid.
-
-