Package org.javacord.api.entity.message
Class MessageBuilder
- java.lang.Object
-
- org.javacord.api.entity.message.MessageBuilder
-
public class MessageBuilder extends Object
This class can help you to create messages.
-
-
Field Summary
Fields Modifier and Type Field Description protected MessageBuilderDelegatedelegateThe message delegate used by this instance.
-
Constructor Summary
Constructors Constructor Description MessageBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MessageBuilderaddActionRow(LowLevelComponent... components)Add multiple low level components, wrapped in an ActionRow, to the message.MessageBuilderaddAttachment(byte[] bytes, String fileName)Adds an attachment to the message.MessageBuilderaddAttachment(BufferedImage image, String fileName)Adds an attachment to the message.MessageBuilderaddAttachment(File file)Adds an attachment to the message.MessageBuilderaddAttachment(InputStream stream, String fileName)Adds an attachment to the message.MessageBuilderaddAttachment(URL url)Adds an attachment to the message.MessageBuilderaddAttachment(Icon icon)Adds an attachment to the message.MessageBuilderaddAttachmentAsSpoiler(byte[] bytes, String fileName)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddAttachmentAsSpoiler(BufferedImage image, String fileName)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddAttachmentAsSpoiler(File file)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddAttachmentAsSpoiler(InputStream stream, String fileName)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddAttachmentAsSpoiler(URL url)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddAttachmentAsSpoiler(Icon icon)Adds an attachment to the message and marks it as spoiler.MessageBuilderaddComponents(HighLevelComponent... components)Add multiple high level components to the message.MessageBuilderaddEmbed(EmbedBuilder embed)Adds an embed to the message.MessageBuilderaddEmbeds(EmbedBuilder... embeds)Adds the embeds to the message.MessageBuilderaddFile(byte[] bytes, String fileName)Adds a file to the message.MessageBuilderaddFile(BufferedImage image, String fileName)Adds a file to the message.MessageBuilderaddFile(File file)Adds a file to the message.MessageBuilderaddFile(InputStream stream, String fileName)Adds a file to the message.MessageBuilderaddFile(URL url)Adds a file to the message and marks it as a spoiler.MessageBuilderaddFile(Icon icon)Adds a file to the message.MessageBuilderaddFileAsSpoiler(byte[] bytes, String fileName)Adds a file to the message and marks it as spoiler.MessageBuilderaddFileAsSpoiler(BufferedImage image, String fileName)Adds a file to the message and marks it as spoiler.MessageBuilderaddFileAsSpoiler(File file)Adds a file to the message and marks it as spoiler.MessageBuilderaddFileAsSpoiler(InputStream stream, String fileName)Adds a file to the message and marks it as spoiler.MessageBuilderaddFileAsSpoiler(URL url)Adds a file to the message and marks it as a spoiler.MessageBuilderaddFileAsSpoiler(Icon icon)Adds a file to the message and marks it as spoiler.MessageBuilderappend(Object object)Appends the string representation of the object (callingString.valueOf(Object)method) to the message.MessageBuilderappend(String message, MessageDecoration... decorations)Appends a sting with or without decoration to the message.MessageBuilderappend(Mentionable entity)Appends a mentionable entity (usually a user or channel) to the message.MessageBuilderappendCode(String language, String code)Appends code to the message.MessageBuilderappendNewLine()Appends a new line to the message.MessageBuildercopy(Message message)Fill the builder's values with a message.static MessageBuilderfromMessage(Message message)Creates a message builder from a message.StringBuildergetStringBuilder()Gets theStringBuilderwhich is used to build the message.MessageBuilderremoveAllComponents()Remove all high-level components from the message.MessageBuilderremoveAllEmbeds()Removes all embeds from the message.MessageBuilderremoveEmbed(EmbedBuilder embed)Removes the embed from the message.MessageBuilderremoveEmbeds(EmbedBuilder... embeds)Removes the embeds from the message.MessageBuilderreplyTo(long messageId)Sets the message to reply to.MessageBuilderreplyTo(Message message)Sets the message to reply to.CompletableFuture<Message>send(TextChannel channel)Sends the message.CompletableFuture<Message>send(Messageable messageable)Sends the message.CompletableFuture<Message>send(User user)Sends the message.CompletableFuture<Message>send(IncomingWebhook webhook)Sends the message.CompletableFuture<Message>sendWithWebhook(DiscordApi api, long webhookId, String webhookToken)Sends the message.CompletableFuture<Message>sendWithWebhook(DiscordApi api, String webhookUrl)Sends the message.CompletableFuture<Message>sendWithWebhook(DiscordApi api, String webhookId, String webhookToken)Sends the message.MessageBuildersetAllowedMentions(AllowedMentions allowedMentions)Controls who will be mentioned if mentions exist in the message.MessageBuildersetContent(String content)Sets the content of the message.MessageBuildersetEmbed(EmbedBuilder embed)Sets the embed of the message (overrides all existing embeds).MessageBuildersetEmbeds(EmbedBuilder... embeds)Sets multiple embeds of the message (overrides all existing embeds).MessageBuildersetNonce(String nonce)Sets the nonce of the message.MessageBuildersetTts(boolean tts)Sets if the message should be text to speech.
-
-
-
Field Detail
-
delegate
protected final MessageBuilderDelegate delegate
The message delegate used by this instance.
-
-
Method Detail
-
fromMessage
public static MessageBuilder fromMessage(Message message)
Creates a message builder from a message.- Parameters:
message- The message to copy.- Returns:
- A message builder which would produce the same text as the given message.
-
copy
public MessageBuilder copy(Message message)
Fill the builder's values with a message.- Parameters:
message- The message to copy.- Returns:
- The current instance in order to chain call methods.
-
addComponents
public MessageBuilder addComponents(HighLevelComponent... components)
Add multiple high level components to the message.- Parameters:
components- The high level components.- Returns:
- The current instance in order to chain call methods.
-
addActionRow
public MessageBuilder addActionRow(LowLevelComponent... components)
Add multiple low level components, wrapped in an ActionRow, to the message.- Parameters:
components- The low level components.- Returns:
- The current instance in order to chain call methods.
-
appendCode
public MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder appendNewLine()
Appends a new line to the message.- Returns:
- The current instance in order to chain call methods.
-
setContent
public MessageBuilder 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.
-
setEmbed
public MessageBuilder setEmbed(EmbedBuilder embed)
Sets the embed of the message (overrides all existing embeds).- Parameters:
embed- The embed to set.- Returns:
- The current instance in order to chain call methods.
-
setEmbeds
public MessageBuilder setEmbeds(EmbedBuilder... embeds)
Sets multiple embeds of the message (overrides all existing embeds).- Parameters:
embeds- The embed to set.- Returns:
- The current instance in order to chain call methods.
-
addEmbed
public MessageBuilder addEmbed(EmbedBuilder embed)
Adds an embed to the message.- Parameters:
embed- The embed to add.- Returns:
- The current isntance in order to chain call methods.
-
setTts
public MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder 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.
-
replyTo
public MessageBuilder replyTo(Message message)
Sets the message to reply to.- Parameters:
message- The the message to reply to.- Returns:
- The current instance in order to chain call methods.
-
replyTo
public MessageBuilder replyTo(long messageId)
Sets the message to reply to.- Parameters:
messageId- The id of the message to reply to.- Returns:
- The current instance in order to chain call methods.
-
removeAllComponents
public MessageBuilder removeAllComponents()
Remove all high-level components from the message.- Returns:
- The current instance in order to chain call methods.
-
addEmbeds
public MessageBuilder 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 MessageBuilder 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 MessageBuilder 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 MessageBuilder removeAllEmbeds()
Removes all embeds from the message.- Returns:
- The current instance in order to chain call methods.
-
setNonce
public MessageBuilder setNonce(String nonce)
Sets the nonce of the message.- Parameters:
nonce- The nonce to set.- 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(User user)
Sends the message.- Parameters:
user- The user to which the message should be sent.- Returns:
- The sent message.
-
send
public CompletableFuture<Message> send(TextChannel channel)
Sends the message.- Parameters:
channel- The channel in which the message should be sent.- Returns:
- The sent 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(Messageable messageable)
Sends the message.- Parameters:
messageable- The receiver of the message.- Returns:
- The sent message.
-
sendWithWebhook
public CompletableFuture<Message> sendWithWebhook(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.
-
sendWithWebhook
public CompletableFuture<Message> sendWithWebhook(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.
-
sendWithWebhook
public CompletableFuture<Message> sendWithWebhook(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.
-
-