Interface MessageCreateRequest<R extends MessageCreateRequest<R>>
- Type Parameters:
R
- The return type for method chaining convenience
- All Superinterfaces:
MessageData
,MessageRequest<R>
- All Known Subinterfaces:
ForumPostAction
,MessageCreateAction
,ReplyCallbackAction
,WebhookMessageCreateAction<T>
- All Known Implementing Classes:
MessageCreateBuilder
-
Method Summary
Modifier and TypeMethodDescriptiondefault R
addActionRow
(Collection<? extends ItemComponent> components) Appends a singleActionRow
to the request.default R
addActionRow
(ItemComponent... components) Appends a singleActionRow
to the request.addComponents
(Collection<? extends LayoutComponent> components) Appends the providedLayoutComponents
to the request.default R
addComponents
(LayoutComponent... components) Appends the providedLayoutComponents
to the request.addContent
(String content) Appends the content to the currently set content of this request.addEmbeds
(Collection<? extends MessageEmbed> embeds) Appends the providedMessageEmbeds
to the request.default R
addEmbeds
(MessageEmbed... embeds) Appends the providedMessageEmbeds
to the request.addFiles
(Collection<? extends FileUpload> files) Appends the providedFileUploads
to the request.default R
addFiles
(FileUpload... files) Appends the providedFileUploads
to the request.default R
applyData
(MessageCreateData data) Applies the providedMessageCreateData
to this request.default R
applyEditData
(MessageEditData data) Applies the providedMessageEditData
to this request.default R
applyMessage
(Message message) Applies all the data of the providedMessage
and attempts to copy it.The configured message attachments asAttachedFile
, this is the opposite ofMessageRequest.setFiles(Collection)
and only returns what was set using that setter.setSuppressedNotifications
(boolean suppressed) Set whether this message should trigger push/desktop notifications to other users.setTTS
(boolean tts) Whether the message should use Text-to-Speech (TTS).Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getAllowedMentions, getComponents, getContent, getEmbeds, getMentionedRoles, getMentionedUsers, isMentionRepliedUser, isSuppressEmbeds
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
mention, mention, mentionRepliedUser, mentionRoles, mentionRoles, mentionRoles, mentionUsers, mentionUsers, mentionUsers, setActionRow, setActionRow, setAllowedMentions, setComponents, setComponents, setContent, setEmbeds, setEmbeds, setFiles, setFiles, setSuppressEmbeds
-
Method Details
-
addContent
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();
- Parameters:
content
- The content to append- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If the provided content isnull
or the accumulated content is longer than 2000 characters
-
addEmbeds
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();
- Parameters:
embeds
- The embeds to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If null is provided or the accumulated embed list is longer than 10
-
addEmbeds
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();
- Parameters:
embeds
- The embeds to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If null is provided or the accumulated embed list is longer than 10
-
addComponents
Appends the providedLayoutComponents
to the request.
UseMessageRequest.setComponents(Collection)
instead, to replace the components entirely.Example
Sending a message with multiple action rows:channel.sendMessageComponents(ActionRow.of(selectMenu)) .addComponents(ActionRow.of(button1, button2)) .queue();
- Parameters:
components
- The layout components to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
-- If
null
is provided - If any of the components is not
message compatible
- If the accumulated list of components is longer than 5
- If
- See Also:
-
addComponents
Appends the providedLayoutComponents
to the request.
UseMessageRequest.setComponents(Collection)
instead, to replace the components entirely.Example
Sending a message with multiple action rows:channel.sendMessageComponents(ActionRow.of(selectMenu)) .addComponents(ActionRow.of(button1, button2)) .queue();
- Parameters:
components
- The layout components to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
-- If
null
is provided - If any of the components is not
message compatible
- If the accumulated list of components is longer than 5
- If
- See Also:
-
addActionRow
Appends a singleActionRow
to the request.
UseMessageRequest.setComponents(Collection)
instead, to replace the components entirely.Example
Sending a message with multiple action rows:channel.sendMessageComponents(ActionRow.of(selectMenu)) .addActionRow(button1, button2) .queue();
- Parameters:
components
- Thecomponents
to add to the action row, must not be empty- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
-- If
null
is provided - If any of the components is not
message compatible
- If the accumulated list of components is longer than 5
- In all the same cases as
ActionRow.of(Collection)
throws an exception
- If
- See Also:
-
addActionRow
Appends a singleActionRow
to the request.
UseMessageRequest.setComponents(Collection)
instead, to replace the components entirely.Example
Sending a message with multiple action rows:channel.sendMessageComponents(ActionRow.of(selectMenu)) .addActionRow(button1, button2) .queue();
- Parameters:
components
- Thecomponents
to add to the action row, must not be empty- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
-- If
null
is provided - If any of the components is not
message compatible
- If the accumulated list of components is longer than 5
- In all the same cases as
ActionRow.of(ItemComponent...)
throws an exception
- If
- See Also:
-
addFiles
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();
- Parameters:
files
- The files to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If null is provided
-
addFiles
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();
- Parameters:
files
- The files to add- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If null is provided
-
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 interfaceMessageData
- Returns:
- The currently configured attachments, or an empty list if none were set yet
- See Also:
-
setTTS
Whether the message should use Text-to-Speech (TTS).Requires
Permission.MESSAGE_TTS
to be enabled.- Parameters:
tts
- True, if the message should use TTS- Returns:
- The same instance for chaining
-
setSuppressedNotifications
Set whether this message should trigger push/desktop notifications to other users.
When a message is suppressed, it will not trigger push/desktop notifications.- Parameters:
suppressed
- True, if this message should not trigger push/desktop notifications- Returns:
- The same reply action, for chaining convenience
-
applyData
Applies the providedMessageCreateData
to this request.- Parameters:
data
- The message create data to apply- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If the data is null
-
applyMessage
Description copied from interface:MessageRequest
Applies all the data of the providedMessage
and attempts to copy it.
This cannot copy the file attachments of the message, they must be manually downloaded and provided toMessageRequest.setFiles(FileUpload...)
.
Theallowed mentions
are not updated to reflect the provided message, and might mention users that the message did not.For edit requests, this will set
MessageEditRequest.setReplace(boolean)
totrue
, and replace the existing message completely.- Specified by:
applyMessage
in interfaceMessageRequest<R extends MessageCreateRequest<R>>
- Parameters:
message
- The message to copy the data from- Returns:
- The same instance for chaining
-
applyEditData
Applies the providedMessageEditData
to this request.
This will only set fields which were explicitly set on theMessageEditBuilder
, unless it was configured to bereplacing
.This will not copy the message's attachments, only any configured
FileUploads
. To copy attachments, you must download them explicitly instead.- Parameters:
data
- The message create data to apply- Returns:
- The same instance for chaining
- Throws:
IllegalArgumentException
- If the data is null
-