Interface MessageEditBuilderMixin<R extends MessageEditRequest<R>>
- All Superinterfaces:
AbstractMessageBuilderMixin<R,
,MessageEditBuilder> MessageData
,MessageEditRequest<R>
,MessageRequest<R>
- All Known Implementing Classes:
MessageEditActionImpl
,MessageEditCallbackActionImpl
,WebhookMessageEditActionImpl
-
Method Summary
Modifier and TypeMethodDescriptiondefault R
applyData
(MessageEditData data) Applies the providedMessageEditData
to this request.default boolean
Whether this request will replace the message and remove everything that is not currently set.default R
setAttachments
(Collection<? extends AttachedFile> attachments) TheAttachedFiles
that should be attached to the message.default R
setFiles
(Collection<? extends FileUpload> files) TheFileUploads
that should be attached to the message.default R
setReplace
(boolean isReplace) Whether to replace the existing message completely.Methods inherited from interface net.dv8tion.jda.internal.utils.message.AbstractMessageBuilderMixin
getAllowedMentions, getAttachments, getBuilder, getComponents, getContent, getEmbeds, getMentionedRoles, getMentionedUsers, isMentionRepliedUser, isSuppressEmbeds, isUsingComponentsV2, mention, mentionRepliedUser, mentionRoles, mentionUsers, setAllowedMentions, setComponents, setContent, setEmbeds, setSuppressEmbeds, useComponentsV2
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getComponentTree
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageEditRequest
applyCreateData, applyMessage, setAttachments
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers, setComponents, setComponents, setEmbeds, setFiles, useComponentsV2
-
Method Details
-
setAttachments
Description copied from interface:MessageEditRequest
TheAttachedFiles
that should be attached to the message.
This will replace all the existing attachments on the message, you can useCollections.emptyList()
ornull
to clear all attachments.Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.Example
// Here "message" is an instance of the Message interface // Creates a list of the currently attached files of the message, important to get the generic parameter of the list right List<AttachedFile> attachments = new ArrayList<>(message.getAttachments()); // The name here will be "cat.png" to discord, what the file is called on your computer is irrelevant and only used to read the data of the image. FileUpload file = FileUpload.fromData(new File("mycat-final-copy.png"), "cat.png"); // Opens the file called "cat.png" and provides the data used for sending // Adds another file to upload in addition the current attachments of the message attachments.add(file); message.editMessage("New content") .setAttachments(attachments) .queue();
- Specified by:
setAttachments
in interfaceMessageEditRequest<R extends MessageEditRequest<R>>
- Parameters:
attachments
- TheAttachedFiles
to attach to the message, null or an empty list will set the attachments to an empty list and remove them from the message- Returns:
- The same instance for chaining
- See Also:
-
setReplace
Description copied from interface:MessageEditRequest
Whether to replace the existing message completely.By default, edit requests will only update the message fields which were explicitly set. Changing this to
true
, will instead replace everything and remove all unset fields.Example Default
A request such as this will only edit thecontent
of the message, and leave any existing embeds or attachments intact.message.editMessage("hello").queue();
Example Replace
A request such as this will replace the entire message, and remove any existing embeds, attachments, components, etc.message.editMessage("hello").setReplace(true).queue();
- Specified by:
setReplace
in interfaceMessageEditRequest<R extends MessageEditRequest<R>>
- Parameters:
isReplace
- True, if only things explicitly set on this request should be present after the message is edited.- Returns:
- The same message edit request builder
-
setFiles
Description copied from interface:MessageRequest
TheFileUploads
that should be attached to the message.
This will replace all the existing attachments on the message, if this is an edit request. You can useMessageEditRequest.setAttachments(Collection)
to keep existing attachments, instead of this method.Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.Example
Create an embed with a custom image, uploaded alongside the message:MessageEmbed embed = new EmbedBuilder() .setDescription("Image of a cute cat") .setImage("attachment://cat.png") // here "cat.png" is the name used in the FileUpload.fromData factory method .build(); // The name here will be "cat.png" to discord, what the file is called on your computer is irrelevant and only used to read the data of the image. FileUpload file = FileUpload.fromData(new File("mycat-final-copy.png"), "cat.png"); // Opens the file called "cat.png" and provides the data used for sending channel.sendMessageEmbeds(embed) .setFiles(file) .queue();
- Specified by:
setFiles
in interfaceAbstractMessageBuilderMixin<R extends MessageEditRequest<R>,
MessageEditBuilder> - Specified by:
setFiles
in interfaceMessageEditRequest<R extends MessageEditRequest<R>>
- Specified by:
setFiles
in interfaceMessageRequest<R extends MessageEditRequest<R>>
- Parameters:
files
- TheFileUploads
to attach to the message, null or an empty list will set the attachments to an empty list and remove them from the message- Returns:
- The same instance for chaining
-
applyData
Description copied from interface:MessageEditRequest
Applies the providedMessageEditData
to this request.Note that this method will only call the setters which were also configured when building the message edit data instance, unless it was set to
replace
.- Specified by:
applyData
in interfaceMessageEditRequest<R extends MessageEditRequest<R>>
- Parameters:
data
- The message edit data to apply- Returns:
- The same instance for chaining
-
isReplace
default boolean isReplace()Description copied from interface:MessageEditRequest
Whether this request will replace the message and remove everything that is not currently set.If this is false, the request will only edit the message fields which were explicitly set.
- Specified by:
isReplace
in interfaceMessageEditRequest<R extends MessageEditRequest<R>>
- Returns:
- True, if this is a replacing request
- See Also:
-