Interface WebhookMessageAction<T>
- All Superinterfaces:
AllowedMentions<WebhookMessageAction<T>>
,RestAction<T>
public interface WebhookMessageAction<T>
extends RestAction<T>, AllowedMentions<WebhookMessageAction<T>>
Extension of a default
RestAction
that allows setting message information before sending!
This is available as return type of all sendMessage/sendFile methods in WebhookClient
.
When this RestAction has been executed all provided files will be closed.
Note that the garbage collector also frees opened file streams when it finalizes the stream object.
- Since:
- 4.3.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault WebhookMessageAction<T>
addActionRow
(Collection<? extends ItemComponent> components) Add oneActionRow
for the message.default WebhookMessageAction<T>
addActionRow
(ItemComponent... components) Add oneActionRow
for the message.default WebhookMessageAction<T>
addActionRows
(Collection<? extends ActionRow> rows) AddActionRows
for the message.addActionRows
(ActionRow... rows) AddActionRows
for the message.addEmbeds
(Collection<? extends MessageEmbed> embeds) AddMessageEmbeds
to this messagedefault WebhookMessageAction<T>
addEmbeds
(MessageEmbed embed, MessageEmbed... other) AddMessageEmbeds
to this messagedefault WebhookMessageAction<T>
addFile
(byte[] data, String name, AttachmentOption... options) Adds the provided byte[] as file data.default WebhookMessageAction<T>
addFile
(File file, String name, AttachmentOption... options) Adds the providedFile
as file data.default WebhookMessageAction<T>
addFile
(File file, AttachmentOption... options) Adds the providedFile
as file data.addFile
(InputStream data, String name, AttachmentOption... options) Adds the providedInputStream
as file data.applyMessage
(Message message) Applies the sendable information of the providedMessage
to this message action settings.setContent
(String content) Set the content for this message.setEphemeral
(boolean ephemeral) Set whether this message should be visible to other users.setTTS
(boolean tts) Enable/Disable Text-To-Speech for the resulting message.Methods inherited from interface net.dv8tion.jda.api.utils.AllowedMentions
allowedMentions, mention, mention, mentionRepliedUser, mentionRoles, mentionRoles, mentionUsers, mentionUsers
Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
addCheck, and, and, complete, complete, completeAfter, deadline, delay, delay, delay, delay, flatMap, flatMap, getCheck, getJDA, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, setCheck, submit, submit, submitAfter, submitAfter, timeout, zip
-
Method Details
-
setEphemeral
Set whether this message should be visible to other users.
When a message is ephemeral, it will only be visible to the user that used the interaction.Ephemeral messages have some limitations and will be removed once the user restarts their client.
Limitations:- Cannot be deleted by the bot
- Cannot contain any files/attachments
- Cannot be reacted to
- Cannot be retrieved
This only works on
InteractionHooks
!- Parameters:
ephemeral
- True, if this message should be invisible for other users- Returns:
- The same message action, for chaining convenience
-
setContent
Set the content for this message.- Parameters:
content
- The new message content- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If the provided content is longer thanMAX_CONTENT_LENGTH
characters
-
setTTS
Enable/Disable Text-To-Speech for the resulting message.- Parameters:
tts
- True, if this should cause a Text-To-Speech effect when sent to the channel- Returns:
- The same message action, for chaining convenience
-
addEmbeds
@Nonnull @CheckReturnValue WebhookMessageAction<T> addEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) AddMessageEmbeds
to this message- Parameters:
embeds
- The message embeds to add- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, or one of the embeds is too big
-
addEmbeds
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addEmbeds(@Nonnull MessageEmbed embed, @Nonnull MessageEmbed... other) AddMessageEmbeds
to this message- Parameters:
embed
- The first message embed to addother
- Additional message embeds to add- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, or one of the embeds is too big
-
addFile
@Nonnull @CheckReturnValue WebhookMessageAction<T> addFile(@Nonnull InputStream data, @Nonnull String name, @Nonnull AttachmentOption... options) Adds the providedInputStream
as file data.
The stream will be closed upon execution!- Parameters:
data
- The InputStream that will be interpreted as file dataname
- The file name that should be used to interpret the type of the given data using the file-name extension. This name is similar to what will be visible throughMessage.Attachment.getFileName()
options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalStateException
- If the file limit of 10 has been reached prior to calling this methodIllegalArgumentException
- If the provided data isnull
or the provided name is blank ornull
InsufficientPermissionException
- If this is targeting a TextChannel and the currently logged in account does not havePermission.MESSAGE_ATTACH_FILES
-
addFile
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addFile(@Nonnull byte[] data, @Nonnull String name, @Nonnull AttachmentOption... options) Adds the provided byte[] as file data.- Parameters:
data
- The byte[] that will be interpreted as file dataname
- The file name that should be used to interpret the type of the given data using the file-name extension. This name is similar to what will be visible throughMessage.Attachment.getFileName()
options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalStateException
- If the file limit of 10 has been reached prior to calling this methodIllegalArgumentException
- If the provided data isnull
or the provided name is blank ornull
or if the provided data exceeds the maximum file size of the currently logged in accountInsufficientPermissionException
- If this is targeting a TextChannel and the currently logged in account does not havePermission.MESSAGE_ATTACH_FILES
- See Also:
-
addFile
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addFile(@Nonnull File file, @Nonnull String name, @Nonnull AttachmentOption... options) Adds the providedFile
as file data.
This method opens aFileInputStream
which will be closed by executing this action!- Parameters:
file
- The File that will be interpreted as file dataname
- The file name that should be used to interpret the type of the given data using the file-name extension. This name is similar to what will be visible throughMessage.Attachment.getFileName()
options
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalStateException
- If the file limit of 10 has been reached prior to calling this methodIllegalArgumentException
- If the provided file isnull
or the provided name is blank ornull
or if the provided file is bigger than the maximum file size of the currently logged in account, or if the provided file does not exist/ is not readableInsufficientPermissionException
- If this is targeting a TextChannel and the currently logged in account does not havePermission.MESSAGE_ATTACH_FILES
- See Also:
-
addFile
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addFile(@Nonnull File file, @Nonnull AttachmentOption... options) Adds the providedFile
as file data.
Shortcut foraddFile(file, file.getName())
with the same side-effects.- Parameters:
file
- The File that will be interpreted as file dataoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalStateException
- If the file limit of 10 has been reached prior to calling this methodIllegalArgumentException
- If the provided file isnull
or if the provided File is bigger than the maximum file size of the currently logged in accountInsufficientPermissionException
- If this is targeting a TextChannel and the currently logged in account does not havePermission.MESSAGE_ATTACH_FILES
- See Also:
-
addActionRow
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addActionRow(@Nonnull ItemComponent... components) Add oneActionRow
for the message.- Parameters:
components
- The components for the action row, such asButton
- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, an invalid number of components is provided, or any customid
is duplicated
-
addActionRow
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addActionRow(@Nonnull Collection<? extends ItemComponent> components) Add oneActionRow
for the message.- Parameters:
components
- The components for the action row, such asButton
- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, an invalid number of components is provided, or any customid
is duplicated
-
addActionRows
@Nonnull @CheckReturnValue default WebhookMessageAction<T> addActionRows(@Nonnull Collection<? extends ActionRow> rows) AddActionRows
for the message.- Parameters:
rows
- The action rows to add- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, more than 5 action rows are provided, or any customid
is duplicated
-
addActionRows
AddActionRows
for the message.- Parameters:
rows
- The action rows to add- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If null is provided, more than 5 action rows are provided, or any customid
is duplicated
-
applyMessage
Applies the sendable information of the providedMessage
to this message action settings.
This will override all existing settings if new settings are available.This does not copy files!
- Parameters:
message
- The Message to apply settings from- Returns:
- The same message action, for chaining convenience
- Throws:
IllegalArgumentException
- If the message contains aMessageEmbed
that exceeds the sendable character limit, seeMessageEmbed.isSendable()
-