Class WebhookMessageBuilder
- java.lang.Object
-
- club.minnced.discord.webhook.send.WebhookMessageBuilder
-
public class WebhookMessageBuilder extends Object
Constructs aWebhookMessage
-
-
Constructor Summary
Constructors Constructor Description WebhookMessageBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description @NotNull WebhookMessageBuilder
addEmbeds(@NotNull WebhookEmbed... embeds)
Adds the provided embeds to the builder@NotNull WebhookMessageBuilder
addEmbeds(@NotNull Collection<? extends WebhookEmbed> embeds)
Adds the provided embeds to the builder@NotNull WebhookMessageBuilder
addFile(@NotNull File file)
Adds the provided file as an attachment to this message.@NotNull WebhookMessageBuilder
addFile(@NotNull String name, @org.jetbrains.annotations.NotNull byte[] data)
Adds the provided data as a file attachment to this message.@NotNull WebhookMessageBuilder
addFile(@NotNull String name, @NotNull File file)
Adds the provided file as an attachment to this message.@NotNull WebhookMessageBuilder
addFile(@NotNull String name, @NotNull InputStream data)
Adds the provided data as a file attachment to this message.@NotNull WebhookMessageBuilder
append(@NotNull String content)
Appends the provided content to the already present content in this message.@NotNull WebhookMessage
build()
Constructs theWebhookMessage
from the current configurations.static @NotNull WebhookMessageBuilder
fromD4J(@NotNull discord4j.core.spec.MessageCreateSpec spec)
Converts a Discord4JMessageCreateSpec
into a compatible WebhookMessageBuilder.static @NotNull WebhookMessageBuilder
fromD4J(@NotNull discord4j.core.spec.MessageEditSpec spec)
Converts a Discord4JMessageCreateSpec
into a compatible WebhookMessageBuilder.static @NotNull WebhookMessageBuilder
fromD4J(@NotNull Consumer<? super discord4j.core.spec.MessageCreateSpec> callback)
Deprecated.Replace withfromD4J(MessageCreateSpec)
static @NotNull WebhookMessageBuilder
fromJavacord(org.javacord.api.entity.message.Message message)
Converts a JavacordMessage
into a compatible WebhookMessageBuilder.static @NotNull WebhookMessageBuilder
fromJDA(@NotNull net.dv8tion.jda.api.utils.messages.MessageCreateData message)
Converts a JDAMessage
into a compatible WebhookMessageBuilder.static @NotNull WebhookMessageBuilder
fromJDA(net.dv8tion.jda.api.entities.Message message)
Converts a JDAMessage
into a compatible WebhookMessageBuilder.int
getFileAmount()
The amount of files currently addedboolean
isEmpty()
Whether this builder is currently empty@NotNull WebhookMessageBuilder
reset()
Clears this builder to its default state@NotNull WebhookMessageBuilder
resetEmbeds()
Clears all embeds currently added this builder@NotNull WebhookMessageBuilder
resetFiles()
Clears all files currently added to this builder@NotNull WebhookMessageBuilder
setAllowedMentions(@NotNull AllowedMentions mentions)
The mention whitelist.@NotNull WebhookMessageBuilder
setAvatarUrl(@Nullable String avatarUrl)
The avatar url to use for this message.@NotNull WebhookMessageBuilder
setContent(@Nullable String content)
Configures the content for this builder@NotNull WebhookMessageBuilder
setEphemeral(boolean ephemeral)
Whether the message should be ephemeral (only works for interaction webhooks).@NotNull WebhookMessageBuilder
setThreadName(@Nullable String name)
Sets the provided name as the name for a newly created thread.@NotNull WebhookMessageBuilder
setTTS(boolean tts)
Whether this message should use Text-to-Speech (TTS)@NotNull WebhookMessageBuilder
setUsername(@Nullable String username)
The username to use for this message.
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Whether this builder is currently empty- Returns:
- True, if this builder is empty
-
getFileAmount
public int getFileAmount()
The amount of files currently added- Returns:
- The amount of currently added files
-
reset
@NotNull public @NotNull WebhookMessageBuilder reset()
Clears this builder to its default state- Returns:
- This builder for chaining convenience
-
resetFiles
@NotNull public @NotNull WebhookMessageBuilder resetFiles()
Clears all files currently added to this builder- Returns:
- This builder for chaining convenience
-
resetEmbeds
@NotNull public @NotNull WebhookMessageBuilder resetEmbeds()
Clears all embeds currently added this builder- Returns:
- This builder for chaining convenience
-
setAllowedMentions
@NotNull public @NotNull WebhookMessageBuilder setAllowedMentions(@NotNull @NotNull AllowedMentions mentions)
The mention whitelist.
SeeAllowedMentions
for more details.- Parameters:
mentions
- The mention whitelist- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided null
-
addEmbeds
@NotNull public @NotNull WebhookMessageBuilder addEmbeds(@NotNull @NotNull WebhookEmbed... embeds)
Adds the provided embeds to the builder- Parameters:
embeds
- The embeds to add- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with nullIllegalStateException
- If more than 10 are added
-
addEmbeds
@NotNull public @NotNull WebhookMessageBuilder addEmbeds(@NotNull @NotNull Collection<? extends WebhookEmbed> embeds)
Adds the provided embeds to the builder- Parameters:
embeds
- The embeds to add- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with nullIllegalStateException
- If more than 10 are added
-
setContent
@NotNull public @NotNull WebhookMessageBuilder setContent(@Nullable @Nullable String content)
Configures the content for this builder- Parameters:
content
- The (nullable) content to use- Returns:
- This builder for chaining convenience
- Throws:
IllegalArgumentException
- If the content is larger than 2000 characters
-
append
@NotNull public @NotNull WebhookMessageBuilder append(@NotNull @NotNull String content)
Appends the provided content to the already present content in this message.- Parameters:
content
- The content to append- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with nullIllegalArgumentException
- If the content exceeds 2000 characters
-
setUsername
@NotNull public @NotNull WebhookMessageBuilder setUsername(@Nullable @Nullable String username)
The username to use for this message.
Each message by a webhook can have a different user appearance. If this is not set it will default the user appearance in the settings of the webhook.- Parameters:
username
- The (nullable) username to use- Returns:
- This builder for chaining convenience
-
setAvatarUrl
@NotNull public @NotNull WebhookMessageBuilder setAvatarUrl(@Nullable @Nullable String avatarUrl)
The avatar url to use for this message.
Each message by a webhook can have a different user appearance. If this is not set it will default the user appearance in the settings of the webhook.- Parameters:
avatarUrl
- The (nullable) avatar url to use- Returns:
- This builder for chaining convenience
-
setTTS
@NotNull public @NotNull WebhookMessageBuilder setTTS(boolean tts)
Whether this message should use Text-to-Speech (TTS)- Parameters:
tts
- True, if this message should use tts- Returns:
- This builder for chaining convenience
-
setEphemeral
@NotNull public @NotNull WebhookMessageBuilder setEphemeral(boolean ephemeral)
Whether the message should be ephemeral (only works for interaction webhooks).- Parameters:
ephemeral
- True if the message should be ephemeral, false otherwise- Returns:
- This builder for chaining convenience
-
addFile
@NotNull public @NotNull WebhookMessageBuilder addFile(@NotNull @NotNull File file)
Adds the provided file as an attachment to this message.
A single message can have up to 10 attachments.- Parameters:
file
- The file to attach- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with null
-
addFile
@NotNull public @NotNull WebhookMessageBuilder addFile(@NotNull @NotNull String name, @NotNull @NotNull File file)
Adds the provided file as an attachment to this message.
A single message can have up to 10 attachments.- Parameters:
name
- The alternative name that should be used insteadfile
- The file to attach- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with null
-
addFile
@NotNull public @NotNull WebhookMessageBuilder addFile(@NotNull @NotNull String name, @NotNull @org.jetbrains.annotations.NotNull byte[] data)
Adds the provided data as a file attachment to this message.
A single message can have up to 10 attachments.- Parameters:
name
- The alternative name that should be useddata
- The data to attach as a file- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with null
-
addFile
@NotNull public @NotNull WebhookMessageBuilder addFile(@NotNull @NotNull String name, @NotNull @NotNull InputStream data)
Adds the provided data as a file attachment to this message.
A single message can have up to 10 attachments.- Parameters:
name
- The alternative name that should be useddata
- The data to attach as a file- Returns:
- This builder for chaining convenience
- Throws:
NullPointerException
- If provided with null
-
setThreadName
@NotNull public @NotNull WebhookMessageBuilder setThreadName(@Nullable @Nullable String name)
Sets the provided name as the name for a newly created thread.
This is only valid for forum/media channels.- Parameters:
name
- The name that should be used- Returns:
- This builder for chaining convenience
-
build
@NotNull public @NotNull WebhookMessage build()
Constructs theWebhookMessage
from the current configurations.- Returns:
- The resulting
WebhookMessage
-
fromJDA
@NotNull public static @NotNull WebhookMessageBuilder fromJDA(@NotNull net.dv8tion.jda.api.entities.Message message)
Converts a JDAMessage
into a compatible WebhookMessageBuilder.- Parameters:
message
- The message- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromJDA
@NotNull public static @NotNull WebhookMessageBuilder fromJDA(@NotNull @NotNull net.dv8tion.jda.api.utils.messages.MessageCreateData message)
Converts a JDAMessage
into a compatible WebhookMessageBuilder.- Parameters:
message
- The message- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromJavacord
@NotNull public static @NotNull WebhookMessageBuilder fromJavacord(@NotNull org.javacord.api.entity.message.Message message)
Converts a JavacordMessage
into a compatible WebhookMessageBuilder.- Parameters:
message
- The message- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull @Deprecated public static @NotNull WebhookMessageBuilder fromD4J(@NotNull @NotNull Consumer<? super discord4j.core.spec.MessageCreateSpec> callback)
Deprecated.Replace withfromD4J(MessageCreateSpec)
Converts a Discord4JMessageCreateSpec
into a compatible WebhookMessageBuilder.- Parameters:
callback
- The callback used to specify the desired message settings- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull public static @NotNull WebhookMessageBuilder fromD4J(@NotNull @NotNull discord4j.core.spec.MessageCreateSpec spec)
Converts a Discord4JMessageCreateSpec
into a compatible WebhookMessageBuilder.- Parameters:
spec
- The message create spec used to specify the desired message settings- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
fromD4J
@NotNull public static @NotNull WebhookMessageBuilder fromD4J(@NotNull @NotNull discord4j.core.spec.MessageEditSpec spec)
Converts a Discord4JMessageCreateSpec
into a compatible WebhookMessageBuilder.- Parameters:
spec
- The message create spec used to specify the desired message settings- Returns:
- WebhookMessageBuilder with the converted data
- Throws:
NullPointerException
- If null is provided
-
-