Interface MessageAction
-
- All Superinterfaces:
AllowedMentions<MessageAction>,java.lang.Appendable,RestAction<Message>
public interface MessageAction extends RestAction<Message>, java.lang.Appendable, AllowedMentions<MessageAction>
Extension of a defaultRestActionthat allows setting message information before sending!This is available as return type of all sendMessage/sendFile methods in
MessageChannel.When updating a Message, unset fields will be ignored by default. To override existing fields with no value (remove content) you can use
override(true). Setting this totruewill cause all fields to be considered and will override the Message entirely causing unset values to be removed from that message.
This can be used to remove existing embeds from a message:message.editMessage("This message had an embed").override(true).queue()When this RestAction has been executed all provided files will be closed. If you decide not to execute this action, you should call
clearFiles()to free resources.
Note that the garbage collector also frees opened file streams when it finalizes the stream object.Example
@Override public void onMessageReceived(MessageReceivedEvent event) { MessageChannel channel = event.getChannel(); channel.sendMessage("This has an embed with an image!") .addFile(new File("dog.png")) .setEmbeds(new EmbedBuilder() .setImage("attachment://dog.png") .build()) .queue(); // this actually sends the information to discord }- Since:
- 3.4.0
- See Also:
Message.editMessage(Message),Message.editMessage(CharSequence),Message.editMessageEmbeds(MessageEmbed...),Message.editMessageFormat(String, Object...),MessageChannel.sendMessage(Message),MessageChannel.sendMessage(CharSequence),MessageChannel.sendMessageEmbeds(MessageEmbed, MessageEmbed...),MessageChannel.sendMessageFormat(String, Object...),MessageChannel.sendFile(File, AttachmentOption...),MessageChannel.sendFile(File, String, AttachmentOption...),MessageChannel.sendFile(InputStream, String, AttachmentOption...),MessageChannel.sendFile(byte[], String, AttachmentOption...)
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default MessageActionaddFile(byte[] data, java.lang.String name, AttachmentOption... options)Adds the provided byte[] as file data.MessageActionaddFile(java.io.File file, java.lang.String name, AttachmentOption... options)Adds the providedFileas file data.default MessageActionaddFile(java.io.File file, AttachmentOption... options)Adds the providedFileas file data.MessageActionaddFile(java.io.InputStream data, java.lang.String name, AttachmentOption... options)Adds the providedInputStreamas file data.MessageActionappend(char c)default MessageActionappend(java.lang.CharSequence csq)MessageActionappend(java.lang.CharSequence csq, int start, int end)default MessageActionappendFormat(java.lang.String format, java.lang.Object... args)Applies the result ofString.format(String, Object...)as content.MessageActionapply(Message message)Applies the sendable information of the providedMessageto this MessageAction settings.MessageActionclearFiles()Clears all previously added files
And closesFileInputStreamsgenerated byaddFile(File, String, net.dv8tion.jda.api.utils.AttachmentOption...).MessageActionclearFiles(java.util.function.BiConsumer<java.lang.String,java.io.InputStream> finalizer)Clears all previously added filesMessageActionclearFiles(java.util.function.Consumer<java.io.InputStream> finalizer)Clears all previously added files
TheclearFiles(BiConsumer)version provides the resource name for more selective operations.MessageActioncontent(java.lang.String content)Overrides existing content with the provided input
The content of a Message may not exceed 2000!MessageActiondeadline(long timestamp)Similar toRestAction.timeout(long, TimeUnit)but schedules a deadline at which the request has to be completed.MessageActionembed(MessageEmbed embed)Deprecated.This is deprecated in favor ofsetEmbeds(MessageEmbed...)MessageActionfailOnInvalidReply(boolean fail)Whether to throw a exception if the referenced message does not exist, when replying to a message.MessageChannelgetChannel()The targetMessageChannelfor this messagestatic java.util.EnumSet<Message.MentionType>getDefaultMentions()Returns the defaultMentionTypespreviously set byMessageAction.setDefaultMentions(Collection).static booleanisDefaultFailOnInvalidReply()Returns the default behavior for replies when the referenced message does not exist.static booleanisDefaultMentionRepliedUser()Returns the default mention behavior for replies.booleanisEdit()Whether this MessageAction will be used to update an existing message.booleanisEmpty()Whether this MessageAction has no values set.MessageActionmentionRepliedUser(boolean mention)Whether to mention the user when replying to a message.MessageActionnonce(java.lang.String nonce)Sets the validation nonce for the outgoing MessageMessageActionoverride(boolean bool)Whether all fields should be considered when editing a messagedefault MessageActionreference(Message message)Make the message a reply to the referenced message.MessageActionreferenceById(long messageId)Make the message a reply to the referenced message.default MessageActionreferenceById(java.lang.String messageId)Make the message a reply to the referenced message.MessageActionreset()Resets this MessageAction to empty stateisEmpty()will result intrueafter this has been performed!default MessageActionretainFiles(java.util.Collection<? extends Message.Attachment> attachments)Removes all attachments that are currently attached to the existing message except for the ones provided.default MessageActionretainFilesById(long... ids)Removes all attachments that are currently attached to the existing message except for the ones provided.default MessageActionretainFilesById(java.lang.String... ids)Removes all attachments that are currently attached to the existing message except for the ones provided.MessageActionretainFilesById(java.util.Collection<java.lang.String> ids)Removes all attachments that are currently attached to the existing message except for the ones provided.default MessageActionsetActionRow(java.util.Collection<? extends Component> components)Create one row of up to 5 interactive messagecomponents.default MessageActionsetActionRow(Component... components)Create one row of up to 5 interactive messagecomponents.default MessageActionsetActionRows(java.util.Collection<? extends ActionRow> rows)Set the action rows for the message.MessageActionsetActionRows(ActionRow... rows)Set the action rows for the message.MessageActionsetCheck(java.util.function.BooleanSupplier checks)Sets the last-second checks before finally executing the http request in the queue.static voidsetDefaultFailOnInvalidReply(boolean fail)Sets the default value forfailOnInvalidReply(boolean)static voidsetDefaultMentionRepliedUser(boolean mention)Sets the default value formentionRepliedUser(boolean)static voidsetDefaultMentions(java.util.Collection<Message.MentionType> allowedMentions)Sets theMentionTypesthat should be parsed by default.MessageActionsetEmbeds(java.util.Collection<? extends MessageEmbed> embeds)Sets up to 10MessageEmbedsthat should be used for this Message.default MessageActionsetEmbeds(MessageEmbed... embeds)Sets up to 10MessageEmbedsthat should be used for this Message.MessageActiontimeout(long timeout, java.util.concurrent.TimeUnit unit)Timeout for this RestAction instance.MessageActiontts(boolean isTTS)Enable/Disable Text-To-Speech for the resulting message.-
Methods inherited from interface net.dv8tion.jda.api.utils.AllowedMentions
allowedMentions, mention, mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers
-
Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
addCheck, and, and, complete, complete, completeAfter, delay, delay, delay, delay, flatMap, flatMap, getCheck, getJDA, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submit, submitAfter, submitAfter, zip
-
-
-
-
Method Detail
-
setDefaultMentions
static void setDefaultMentions(@Nullable java.util.Collection<Message.MentionType> allowedMentions)Sets theMentionTypesthat should be parsed by default. This just sets the default for all MessageActions and can be overridden on a per-action basis usingAllowedMentions.allowedMentions(Collection).
If a message is sent with an empty Set of MentionTypes, then it will not ping any User, Role or@everyone/@here, while still showing up as mention tag.If
nullis provided to this method, then all Types will be pingable (unless whitelisting via one of themention*methods is used).Example
// Disable EVERYONE and HERE mentions by default (to avoid mass ping) EnumSet<Message.MentionType> deny = EnumSet.of(Message.MentionType.EVERYONE, Message.MentionType.HERE); MessageAction.setDefaultMentions(EnumSet.complementOf(deny));- Parameters:
allowedMentions- MentionTypes that are allowed to being parsed and pinged.nullto disable and allow all mentions.
-
getDefaultMentions
@Nonnull static java.util.EnumSet<Message.MentionType> getDefaultMentions()
Returns the defaultMentionTypespreviously set byMessageAction.setDefaultMentions(Collection).- Returns:
- Default mentions set by MessageAction.setDefaultMentions(Collection)
-
setDefaultMentionRepliedUser
static void setDefaultMentionRepliedUser(boolean mention)
Sets the default value formentionRepliedUser(boolean)Default: true
- Parameters:
mention- True, if replies should mention by default
-
isDefaultMentionRepliedUser
static boolean isDefaultMentionRepliedUser()
Returns the default mention behavior for replies.
If this istruethen all replies will mention the author of the target message by default. You can specify this individually withmentionRepliedUser(boolean)for each message.Default: true
- Returns:
- True, if replies mention by default
-
setDefaultFailOnInvalidReply
static void setDefaultFailOnInvalidReply(boolean fail)
Sets the default value forfailOnInvalidReply(boolean)Default: false
- Parameters:
fail- True, to throw a exception if the referenced message does not exist
-
isDefaultFailOnInvalidReply
static boolean isDefaultFailOnInvalidReply()
Returns the default behavior for replies when the referenced message does not exist.
If this istruethen all replies will throw an exception if the referenced message does not exist. You can specify this individually withfailOnInvalidReply(boolean)for each message.Default: false
- Returns:
- True, to throw a exception if the referenced message does not exist
-
setCheck
@Nonnull MessageAction setCheck(@Nullable java.util.function.BooleanSupplier checks)
Description copied from interface:RestActionSets the last-second checks before finally executing the http request in the queue.
If the provided supplier evaluates tofalseor throws an exception this will not be finished. When an exception is thrown from the supplier it will be provided to the failure callback.- Specified by:
setCheckin interfaceRestAction<Message>- Parameters:
checks- The checks to run before executing the request, ornullto run no checks- Returns:
- The current RestAction for chaining convenience
- See Also:
RestAction.getCheck(),RestAction.addCheck(BooleanSupplier)
-
timeout
@Nonnull MessageAction timeout(long timeout, @Nonnull java.util.concurrent.TimeUnit unit)
Description copied from interface:RestActionTimeout for this RestAction instance.
If the request doesn't get executed within the timeout it will fail.When a RestAction times out, it will fail with a
TimeoutException. This is the same asdeadline(System.currentTimeMillis() + unit.toMillis(timeout)).Example
action.timeout(10, TimeUnit.SECONDS) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds- Specified by:
timeoutin interfaceRestAction<Message>- Parameters:
timeout- The timeout to useunit-Unitfor the timeout value- Returns:
- The same RestAction instance with the applied timeout
- See Also:
RestAction.setDefaultTimeout(long, TimeUnit)
-
deadline
@Nonnull MessageAction deadline(long timestamp)
Description copied from interface:RestActionSimilar toRestAction.timeout(long, TimeUnit)but schedules a deadline at which the request has to be completed.
If the deadline is reached, the request will fail with aTimeoutException.This does not mean that the request will immediately timeout when the deadline is reached. JDA will check the deadline right before executing the request or within intervals in a worker thread. This only means the request will timeout if the deadline has passed.
Example
action.deadline(System.currentTimeMillis() + 10000) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds- Specified by:
deadlinein interfaceRestAction<Message>- Parameters:
timestamp- Millisecond timestamp at which the request will timeout- Returns:
- The same RestAction with the applied deadline
- See Also:
RestAction.timeout(long, TimeUnit),RestAction.setDefaultTimeout(long, TimeUnit)
-
getChannel
@Nonnull MessageChannel getChannel()
The targetMessageChannelfor this message- Returns:
- The target channel
-
isEmpty
boolean isEmpty()
Whether this MessageAction has no values set.
Trying to execute withisEmpty() == truewill result in anIllegalStateException!This does not check for files!
- Returns:
- True, if no settings have been applied
-
isEdit
boolean isEdit()
Whether this MessageAction will be used to update an existing message.- Returns:
- True, if this MessageAction targets an existing message
-
apply
@Nonnull @CheckReturnValue MessageAction apply(@Nullable Message message)
Applies the sendable information of the providedMessageto this MessageAction settings.
This will override all existing settings if new settings are available.This does not copy files!
- Parameters:
message- The nullable Message to apply settings from- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the message contains aMessageEmbedthat exceeds the sendable character limit, seeMessageEmbed.isSendable()
-
referenceById
@Nonnull @CheckReturnValue MessageAction referenceById(long messageId)
Make the message a reply to the referenced message.
You can only reply to messages from the same channel!
This will mention the author of the target message. You can disable this throughmentionRepliedUser(boolean).
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withfailOnInvalidReply(boolean).This requires
Permission.MESSAGE_HISTORYin the channel! You cannot reply to system messages such asCHANNEL_PINNED_ADDand similar.- Parameters:
messageId- The target message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the provided ID is null or not a valid snowflakejava.lang.UnsupportedOperationException- If the provided message is from aMessageBuilder- Since:
- 4.2.1
-
referenceById
@Nonnull @CheckReturnValue default MessageAction referenceById(@Nonnull java.lang.String messageId)
Make the message a reply to the referenced message.
You can only reply to messages from the same channel!
This will mention the author of the target message. You can disable this throughmentionRepliedUser(boolean).
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withfailOnInvalidReply(boolean).This requires
Permission.MESSAGE_HISTORYin the channel! You cannot reply to system messages such asCHANNEL_PINNED_ADDand similar.- Parameters:
messageId- The target message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the provided ID is null or not a valid snowflakejava.lang.UnsupportedOperationException- If the provided message is from aMessageBuilder- Since:
- 4.2.1
-
reference
@Nonnull @CheckReturnValue default MessageAction reference(@Nonnull Message message)
Make the message a reply to the referenced message.
You can only reply to messages from the same channel!
This will mention the author of the target message. You can disable this throughmentionRepliedUser(boolean).
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withfailOnInvalidReply(boolean).This requires
Permission.MESSAGE_HISTORYin the channel! You cannot reply to system messages such asCHANNEL_PINNED_ADDand similar.- Parameters:
message- The target message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the provided message is nulljava.lang.UnsupportedOperationException- If the provided message is from aMessageBuilder- Since:
- 4.2.1
-
mentionRepliedUser
@Nonnull @CheckReturnValue MessageAction mentionRepliedUser(boolean mention)
Whether to mention the user when replying to a message.
This only matters in combination withreference(Message)andreferenceById(long)!This is true by default but can be configured using
setDefaultMentionRepliedUser(boolean)!- Specified by:
mentionRepliedUserin interfaceAllowedMentions<MessageAction>- Parameters:
mention- True, to mention the author if the referenced message- Returns:
- Updated MessageAction for chaining convenience
- Since:
- 4.2.1
-
failOnInvalidReply
@Nonnull @CheckReturnValue MessageAction failOnInvalidReply(boolean fail)
Whether to throw a exception if the referenced message does not exist, when replying to a message.
This only matters in combination withreference(Message)andreferenceById(long)!This is false by default but can be configured using
setDefaultFailOnInvalidReply(boolean)!- Parameters:
fail- True, to throw a exception if the referenced message does not exist- Returns:
- Updated MessageAction for chaining convenience
- Since:
- 4.2.1
-
tts
@Nonnull @CheckReturnValue MessageAction tts(boolean isTTS)
Enable/Disable Text-To-Speech for the resulting message.
This is only relevant to MessageActions that are notisEdit() == true!- Parameters:
isTTS- True, if this should cause a Text-To-Speech effect when sent to the channel- Returns:
- Updated MessageAction for chaining convenience
-
reset
@Nonnull @CheckReturnValue MessageAction reset()
Resets this MessageAction to empty stateisEmpty()will result intrueafter this has been performed!Convenience over using
content(null).nonce(null).setEmbeds(emptyList()).tts(false).override(false).clearFiles()- Returns:
- Updated MessageAction for chaining convenience
-
nonce
@Nonnull @CheckReturnValue MessageAction nonce(@Nullable java.lang.String nonce)
Sets the validation nonce for the outgoing MessageFor more information see
MessageBuilder.setNonce(String)andMessage.getNonce()- Parameters:
nonce- The nonce that shall be used- Returns:
- Updated MessageAction for chaining convenience
- See Also:
Message.getNonce(),MessageBuilder.setNonce(String), Cryptographic Nonce - Wikipedia
-
content
@Nonnull @CheckReturnValue MessageAction content(@Nullable java.lang.String content)
Overrides existing content with the provided input
The content of a Message may not exceed 2000!- Parameters:
content- Sets the specified content and overrides previous content ornullto reset content- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the provided content exceeds the 2000 character limit
-
embed
@Nonnull @CheckReturnValue @Deprecated @ForRemoval(deadline="5.0.0") @ReplaceWith("setEmbeds(embed)") @DeprecatedSince("4.4.0") MessageAction embed(@Nullable MessageEmbed embed)
Deprecated.This is deprecated in favor ofsetEmbeds(MessageEmbed...)Sets theMessageEmbedthat should be used for this Message. Refer toEmbedBuilderfor more information.- Parameters:
embed- TheMessageEmbedthat should be attached to this message,nullto use no embed.- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the provided MessageEmbed is not sendable according toMessageEmbed.isSendable()! If the provided MessageEmbed is an unknown implementation this operation will fail as we are unable to deserialize it.
-
setEmbeds
@Nonnull @CheckReturnValue MessageAction setEmbeds(@Nonnull java.util.Collection<? extends MessageEmbed> embeds)
Sets up to 10MessageEmbedsthat should be used for this Message. Refer toEmbedBuilderfor more information.- Parameters:
embeds- TheMessageEmbedsthat should be attached to this message,Collections.emptyList()to use no embed.- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the provided MessageEmbeds is not sendable according toMessageEmbed.isSendable()! If the provided MessageEmbed is an unknown implementation this operation will fail as we are unable to deserialize it.
-
setEmbeds
@Nonnull @CheckReturnValue default MessageAction setEmbeds(@Nonnull MessageEmbed... embeds)
Sets up to 10MessageEmbedsthat should be used for this Message. Refer toEmbedBuilderfor more information.- Parameters:
embeds- TheMessageEmbedsthat should be attached to this message,Collections.emptyList()to use no embed.- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the provided MessageEmbeds is not sendable according toMessageEmbed.isSendable()! If the provided MessageEmbed is an unknown implementation this operation will fail as we are unable to deserialize it.
-
append
@Nonnull @CheckReturnValue default MessageAction append(@Nonnull java.lang.CharSequence csq)
- Specified by:
appendin interfacejava.lang.Appendable- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the appended CharSequence is too big and will cause the content to exceed the 2000 character limit
-
append
@Nonnull @CheckReturnValue MessageAction append(@Nullable java.lang.CharSequence csq, int start, int end)
- Specified by:
appendin interfacejava.lang.Appendable- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the appended CharSequence is too big and will cause the content to exceed the 2000 character limit
-
append
@Nonnull @CheckReturnValue MessageAction append(char c)
- Specified by:
appendin interfacejava.lang.Appendable- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the appended CharSequence is too big and will cause the content to exceed the 2000 character limit
-
appendFormat
@Nonnull @CheckReturnValue default MessageAction appendFormat(@Nonnull java.lang.String format, java.lang.Object... args)
Applies the result ofString.format(String, Object...)as content.For more information of formatting review the
Formatterdocumentation!- Parameters:
format- The format Stringargs- The arguments that should be used for conversion- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If the appended formatting is too big and will cause the content to exceed the 2000 character limitjava.util.IllegalFormatException- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
-
addFile
@Nonnull @CheckReturnValue MessageAction addFile(@Nonnull java.io.InputStream data, @Nonnull java.lang.String name, @Nonnull AttachmentOption... options)
Adds the providedInputStreamas file data.
The stream will be closed upon execution!To reset all files use
clearFiles()- 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:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalStateException- If the file limit of 10 has been reached prior to calling this methodjava.lang.IllegalArgumentException- If the provided data isnullor the provided name is blank ornullInsufficientPermissionException- If this is targeting a TextChannel and the currently logged in account does not havePermission.MESSAGE_ATTACH_FILES
-
addFile
@Nonnull @CheckReturnValue default MessageAction addFile(@Nonnull byte[] data, @Nonnull java.lang.String name, @Nonnull AttachmentOption... options)
Adds the provided byte[] as file data.To reset all files use
clearFiles()- 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:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalStateException- If the file limit of 10 has been reached prior to calling this methodjava.lang.IllegalArgumentException- If the provided data isnullor the provided name is blank ornullor 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:
SelfUser.getAllowedFileSize()
-
addFile
@Nonnull @CheckReturnValue default MessageAction addFile(@Nonnull java.io.File file, @Nonnull AttachmentOption... options)
Adds the providedFileas 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:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalStateException- If the file limit of 10 has been reached prior to calling this methodjava.lang.IllegalArgumentException- If the provided file isnullor 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:
SelfUser.getAllowedFileSize()
-
addFile
@Nonnull @CheckReturnValue MessageAction addFile(@Nonnull java.io.File file, @Nonnull java.lang.String name, @Nonnull AttachmentOption... options)
Adds the providedFileas file data.To reset all files use
clearFiles()
This method opens aFileInputStreamwhich will be closed by executing this action or usingclearFiles()!- 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:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalStateException- If the file limit of 10 has been reached prior to calling this methodjava.lang.IllegalArgumentException- If the provided file isnullor the provided name is blank ornullor 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:
SelfUser.getAllowedFileSize()
-
clearFiles
@Nonnull @CheckReturnValue MessageAction clearFiles()
Clears all previously added files
And closesFileInputStreamsgenerated byaddFile(File, String, net.dv8tion.jda.api.utils.AttachmentOption...).
To close all stream (including ones given byaddFile(InputStream, String, net.dv8tion.jda.api.utils.AttachmentOption...)) useclearFiles(Consumer).- Returns:
- Updated MessageAction for chaining convenience
- See Also:
clearFiles(BiConsumer)
-
clearFiles
@Nonnull @CheckReturnValue MessageAction clearFiles(@Nonnull java.util.function.BiConsumer<java.lang.String,java.io.InputStream> finalizer)
Clears all previously added files- Parameters:
finalizer- BiConsumer useful to close remaining resources, the consumer will receive the name as a string parameter and the resource asInputStream.- Returns:
- Updated MessageAction for chaining convenience
- See Also:
Closeable
-
clearFiles
@Nonnull @CheckReturnValue MessageAction clearFiles(@Nonnull java.util.function.Consumer<java.io.InputStream> finalizer)
Clears all previously added files
TheclearFiles(BiConsumer)version provides the resource name for more selective operations.- Parameters:
finalizer- Consumer useful to close remaining resources, the consumer will receive only the resource in the form of anInputStream- Returns:
- Updated MessageAction for chaining convenience
- See Also:
Closeable
-
retainFilesById
@Nonnull @CheckReturnValue MessageAction retainFilesById(@Nonnull java.util.Collection<java.lang.String> ids)
Removes all attachments that are currently attached to the existing message except for the ones provided.
For exampleretainFilesById(Arrays.asList("123"))would remove all attachments except for the one with the id 123.To remove all attachments from the message you can pass an empty list.
- Parameters:
ids- The ids for the attachments which should be retained on the message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the ids is null or not a valid snowflake
-
retainFilesById
@Nonnull @CheckReturnValue default MessageAction retainFilesById(@Nonnull java.lang.String... ids)
Removes all attachments that are currently attached to the existing message except for the ones provided.
For exampleretainFilesById(Arrays.asList("123"))would remove all attachments except for the one with the id 123.To remove all attachments from the message you can pass an empty list.
- Parameters:
ids- The ids for the attachments which should be retained on the message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the ids is null or not a valid snowflake
-
retainFilesById
@Nonnull @CheckReturnValue default MessageAction retainFilesById(long... ids)
Removes all attachments that are currently attached to the existing message except for the ones provided.
For exampleretainFilesById(Arrays.asList("123"))would remove all attachments except for the one with the id 123.To remove all attachments from the message you can pass an empty list.
- Parameters:
ids- The ids for the attachments which should be retained on the message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the ids is null or not a valid snowflake
-
retainFiles
@Nonnull @CheckReturnValue default MessageAction retainFiles(@Nonnull java.util.Collection<? extends Message.Attachment> attachments)
Removes all attachments that are currently attached to the existing message except for the ones provided.
For exampleretainFiles(message.getAttachments().subList(1, message.getAttachments().size()))would only remove the first attachment from the message.To remove all attachments from the message you can pass an empty list.
- Parameters:
attachments- The attachments which should be retained on the message- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If any of the ids is null or not a valid snowflake
-
setActionRows
@Nonnull @CheckReturnValue default MessageAction setActionRows(@Nonnull java.util.Collection<? extends ActionRow> rows)
Set the action rows for the message.- Parameters:
rows- The new action rows- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If null is provided or more than 5 actions rows are provided
-
setActionRows
@Nonnull @CheckReturnValue MessageAction setActionRows(@Nonnull ActionRow... rows)
Set the action rows for the message.- Parameters:
rows- The new action rows- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If null is provided or more than 5 actions rows are provided
-
setActionRow
@Nonnull @CheckReturnValue default MessageAction setActionRow(@Nonnull java.util.Collection<? extends Component> components)
Create one row of up to 5 interactive messagecomponents.
This is identical tosetActionRows(ActionRow.of(components))- Parameters:
components- The components for this action row- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If anything is null, empty, or an invalid number of components are provided- See Also:
ActionRow.of(Collection)
-
setActionRow
@Nonnull @CheckReturnValue default MessageAction setActionRow(@Nonnull Component... components)
Create one row of up to 5 interactive messagecomponents.
This is identical tosetActionRows(ActionRow.of(components))- Parameters:
components- The components for this action row- Returns:
- Updated MessageAction for chaining convenience
- Throws:
java.lang.IllegalArgumentException- If anything is null, empty, or an invalid number of components are provided- See Also:
ActionRow.of(Component...)
-
override
@Nonnull @CheckReturnValue MessageAction override(boolean bool)
Whether all fields should be considered when editing a message- Parameters:
bool- True, to override all fields even if they are not set- Returns:
- Updated MessageAction for chaining convenience
-
-