Class WebhookMessage
- java.lang.Object
-
- club.minnced.discord.webhook.send.WebhookMessage
-
public class WebhookMessage extends Object
Send-only message for aWebhookClient
AReadonlyMessage
can be sent by first converting it to a WebhookMessage withfrom(club.minnced.discord.webhook.receive.ReadonlyMessage)
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_EMBEDS
Maximum amount of embeds a single message can hold (10)static int
MAX_FILES
Maximum amount of files a single message can hold (10)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull WebhookMessage
asEphemeral(boolean ephemeral)
Returns a new WebhookMessage instance with the ephemeral flag turned on/off (true/false).static @NotNull WebhookMessage
embeds(@NotNull WebhookEmbed first, @NotNull WebhookEmbed... embeds)
Creates a WebhookMessage from the provided embeds.static @NotNull WebhookMessage
embeds(@NotNull Collection<WebhookEmbed> embeds)
Creates a WebhookMessage from the provided embeds.static @NotNull WebhookMessage
files(@NotNull String name1, @NotNull Object data1, @NotNull Object... attachments)
Creates a WebhookMessage from the provided attachments.static @NotNull WebhookMessage
files(@NotNull Map<String,?> attachments)
Creates a WebhookMessage from the provided attachments.static @NotNull WebhookMessage
from(@NotNull ReadonlyMessage message)
Converts aReadonlyMessage
to a WebhookMessage.@Nullable MessageAttachment[]
getAttachments()
The attachments for this message@Nullable String
getAvatarUrl()
The avatar url for this message@NotNull RequestBody
getBody()
Provides aRequestBody
of this message.@Nullable String
getContent()
The content for this message@NotNull List<WebhookEmbed>
getEmbeds()
The embeds for this messageint
getFlags()
The message flags used for this message.@Nullable String
getUsername()
The username for this messageboolean
isFile()
Whether this message contains filesboolean
isTTS()
Whether this message should use Text-to-Speech (TTS)
-
-
-
Field Detail
-
MAX_FILES
public static final int MAX_FILES
Maximum amount of files a single message can hold (10)- See Also:
- Constant Field Values
-
MAX_EMBEDS
public static final int MAX_EMBEDS
Maximum amount of embeds a single message can hold (10)- See Also:
- Constant Field Values
-
-
Method Detail
-
getUsername
@Nullable public @Nullable String getUsername()
The username for this message- Returns:
- Possibly-null username
-
getAvatarUrl
@Nullable public @Nullable String getAvatarUrl()
The avatar url for this message- Returns:
- Possibly-null avatar url
-
getContent
@Nullable public @Nullable String getContent()
The content for this message- Returns:
- Possibly-null content
-
getEmbeds
@NotNull public @NotNull List<WebhookEmbed> getEmbeds()
The embeds for this message- Returns:
- The embeds
-
getAttachments
@Nullable public @Nullable MessageAttachment[] getAttachments()
The attachments for this message- Returns:
- The attachments
-
isTTS
public boolean isTTS()
Whether this message should use Text-to-Speech (TTS)- Returns:
- True, if this message will use tts
-
getFlags
public int getFlags()
The message flags used for this message.- Returns:
- The flags
-
asEphemeral
@NotNull public @NotNull WebhookMessage asEphemeral(boolean ephemeral)
Returns a new WebhookMessage instance with the ephemeral flag turned on/off (true/false).
This instance remains unchanged and a new instance is returned.- Parameters:
ephemeral
- Whether to make this message ephemeral- Returns:
- New WebhookMessage instance
-
from
@NotNull public static @NotNull WebhookMessage from(@NotNull @NotNull ReadonlyMessage message)
Converts aReadonlyMessage
to a WebhookMessage.
This does not convert attachments.- Parameters:
message
- The message to convert- Returns:
- A WebhookMessage copy
- Throws:
NullPointerException
- If provided with null
-
embeds
@NotNull public static @NotNull WebhookMessage embeds(@NotNull @NotNull WebhookEmbed first, @NotNull @NotNull WebhookEmbed... embeds)
Creates a WebhookMessage from the provided embeds. A message can hold up to 10 embeds.- Parameters:
first
- The first embedembeds
- Optional additional embeds for the message- Returns:
- A WebhookMessage for the embeds
- Throws:
NullPointerException
- If provided with nullIllegalArgumentException
- If more than 10 are provided
-
embeds
@NotNull public static @NotNull WebhookMessage embeds(@NotNull @NotNull Collection<WebhookEmbed> embeds)
Creates a WebhookMessage from the provided embeds. A message can hold up to 10 embeds.- Parameters:
embeds
- Embeds for the message- Returns:
- A WebhookMessage for the embeds
- Throws:
NullPointerException
- If provided with nullIllegalArgumentException
- If more than 10 are provided
-
files
@NotNull public static @NotNull WebhookMessage files(@NotNull @NotNull Map<String,?> attachments)
Creates a WebhookMessage from the provided attachments.
A message can hold up to 10 attachments and a total of 8MiB of data.- Parameters:
attachments
- The attachments to add, keys are the alternative names for each attachment- Returns:
- A WebhookMessage for the attachments
- Throws:
NullPointerException
- If provided with nullIllegalArgumentException
- If no attachments are provided or more than 10
-
files
@NotNull public static @NotNull WebhookMessage files(@NotNull @NotNull String name1, @NotNull @NotNull Object data1, @NotNull @NotNull Object... attachments)
Creates a WebhookMessage from the provided attachments.
A message can hold up to 10 attachments and a total of 8MiB of data.The files are provided in pairs of Name->Data similar to the first 2 arguments.
The allowed data types arebyte[] | InputStream | File
- Parameters:
name1
- The alternative name of the first attachmentdata1
- The first attachment, must be of typebyte[] | InputStream | File
attachments
- Optional additional attachments to add, pairs of String->Data- Returns:
- A WebhookMessage for the attachments
- Throws:
NullPointerException
- If provided with nullIllegalArgumentException
- If no attachments are provided or more than 10 or the additional arguments are not an even count or an invalid format
-
isFile
public boolean isFile()
Whether this message contains files- Returns:
- True, if this message contains files
-
getBody
@NotNull public @NotNull RequestBody getBody()
Provides aRequestBody
of this message.
This is used internally for executing webhooks through HTTP requests.- Returns:
- The request body
-
-