Interface MessageCreateBuilderMixin<R extends MessageCreateRequest<R>>
- All Superinterfaces:
AbstractMessageBuilderMixin<R,
,MessageCreateBuilder> MessageCreateRequest<R>
,MessageData
,MessageRequest<R>
- All Known Implementing Classes:
ForumPostActionImpl
,MessageCreateActionImpl
,ReplyCallbackActionImpl
,WebhookMessageCreateActionImpl
-
Method Summary
Modifier and TypeMethodDescriptiondefault R
addComponents
(Collection<? extends MessageTopLevelComponent> components) Appends the providedMessageTopLevelComponents
to the request.default R
addContent
(String content) Appends the content to the currently set content of this request.default R
addEmbeds
(Collection<? extends MessageEmbed> embeds) Appends the providedMessageEmbeds
to the request.default R
addFiles
(Collection<? extends FileUpload> files) Appends the providedFileUploads
to the request.default List
<FileUpload> The configured message attachments asAttachedFile
, this is the opposite ofMessageRequest.setFiles(Collection)
and only returns what was set using that setter.default MessagePollData
getPoll()
The poll attached to this messagedefault R
setFiles
(Collection<? extends FileUpload> files) TheFileUploads
that should be attached to the message.default R
setPoll
(MessagePollData poll) Add a poll to this message.default R
setSuppressedNotifications
(boolean suppressed) Set whether this message should trigger push/desktop notifications to other users.default R
setTTS
(boolean tts) Whether the message should use Text-to-Speech (TTS).default R
setVoiceMessage
(boolean voiceMessage) Whether this message should be considered a voice message.Methods inherited from interface net.dv8tion.jda.internal.utils.message.AbstractMessageBuilderMixin
getAllowedMentions, 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.MessageCreateRequest
addComponents, addComponents, addEmbeds, addFiles, applyData, applyEditData, applyMessage
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getComponentTree
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers, setComponents, setComponents, setEmbeds, setFiles, useComponentsV2
-
Method Details
-
addContent
Description copied from interface:MessageCreateRequest
Appends the content to the currently set content of this request.
UseMessageRequest.setContent(String)
instead, to replace the content entirely.Example
Sending a message with the content"Hello World!"
:channel.sendMessage("Hello ").addContent("World!").queue();
- Specified by:
addContent
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
content
- The content to append- Returns:
- The same instance for chaining
-
addEmbeds
Description copied from interface:MessageCreateRequest
Appends the providedMessageEmbeds
to the request.
UseMessageRequest.setEmbeds(Collection)
instead, to replace the embeds entirely.Example
Sending a message with multiple embeds:channel.sendMessageEmbeds(embed1).addEmbeds(embed2).queue();
- Specified by:
addEmbeds
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
embeds
- The embeds to add- Returns:
- The same instance for chaining
-
addComponents
@Nonnull default R addComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:MessageCreateRequest
Appends the providedMessageTopLevelComponents
to the request.
UseMessageRequest.setComponents(Collection)
instead, to replace the components entirely.Example
Sending a message with multiple action rows:final List<MessageTopLevelComponent> list = new ArrayList<>(); list.add(ActionRow.of(selectMenu); // first row list.add(ActionRow.of(button1, button2)); // second row (shows below the first) channel.sendMessage("Content here") .addComponents(list) .queue();
- Specified by:
addComponents
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
components
- TheMessageTopLevelComponents
to add, can contain up to 5 V1 components. There are no limits for V2 components outside the total tree size (40).- Returns:
- The same instance for chaining
-
addFiles
Description copied from interface:MessageCreateRequest
Appends the providedFileUploads
to the request.
UseMessageRequest.setFiles(Collection)
instead, to replace the file attachments entirely.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
Sending a message with multiple files:channel.sendFiles(file1).addFiles(file2).queue();
- Specified by:
addFiles
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
files
- The files to add- Returns:
- The same instance for chaining
-
getPoll
Description copied from interface:MessageCreateRequest
The poll attached to this message- Specified by:
getPoll
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Returns:
- The attached poll, or null if no poll is present
-
setPoll
Description copied from interface:MessageCreateRequest
Add a poll to this message.- Specified by:
setPoll
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
poll
- The poll to send- Returns:
- The same instance for chaining
- See Also:
-
setTTS
Description copied from interface:MessageCreateRequest
Whether the message should use Text-to-Speech (TTS).Requires
Permission.MESSAGE_TTS
to be enabled.- Specified by:
setTTS
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
tts
- True, if the message should use TTS- Returns:
- The same instance for chaining
-
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 MessageCreateRequest<R>,
MessageCreateBuilder> - Specified by:
setFiles
in interfaceMessageRequest<R extends MessageCreateRequest<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
-
getAttachments
Description copied from interface:MessageData
The configured message attachments asAttachedFile
, this is the opposite ofMessageRequest.setFiles(Collection)
and only returns what was set using that setter.For message edit requests, this will not be the current file attachments of the message.
- Specified by:
getAttachments
in interfaceAbstractMessageBuilderMixin<R extends MessageCreateRequest<R>,
MessageCreateBuilder> - Specified by:
getAttachments
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Specified by:
getAttachments
in interfaceMessageData
- Returns:
- The currently configured attachments, or an empty list if none were set yet
- See Also:
-
setSuppressedNotifications
Description copied from interface:MessageCreateRequest
Set whether this message should trigger push/desktop notifications to other users.
When a message is suppressed, it will not trigger push/desktop notifications.- Specified by:
setSuppressedNotifications
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
suppressed
- True, if this message should not trigger push/desktop notifications- Returns:
- The same instance for chaining
-
setVoiceMessage
Description copied from interface:MessageCreateRequest
Whether this message should be considered a voice message.
Voice messages must upload a valid voice message attachment, usingFileUpload.asVoiceMessage(MediaType, byte[], double)
.- Specified by:
setVoiceMessage
in interfaceMessageCreateRequest<R extends MessageCreateRequest<R>>
- Parameters:
voiceMessage
- True, if this message is a voice message. Turned on automatically if attachment is a valid voice message attachment.- Returns:
- The same instance for chaining
-