Interface AbstractMessageBuilderMixin<R extends MessageRequest<R>,B extends AbstractMessageBuilder<?,B>>
- All Superinterfaces:
MessageData
,MessageRequest<R>
- All Known Subinterfaces:
MessageCreateBuilderMixin<R>
,MessageEditBuilderMixin<R>
- All Known Implementing Classes:
ForumPostActionImpl
,MessageCreateActionImpl
,MessageEditActionImpl
,MessageEditCallbackActionImpl
,ReplyCallbackActionImpl
,WebhookMessageCreateActionImpl
,WebhookMessageEditActionImpl
-
Method Summary
Modifier and TypeMethodDescriptiondefault EnumSet
<Message.MentionType> The mention types which are whitelisted.default List
<? extends AttachedFile> The configured message attachments asAttachedFile
, this is the opposite ofMessageRequest.setFiles(Collection)
and only returns what was set using that setter.default List
<MessageTopLevelComponentUnion> The configured message components, this is the opposite ofMessageRequest.setComponents(Collection)
and only returns what was set using that setter.default String
The configured message content, this is the opposite forMessageRequest.setContent(String)
and only returns what was set using that setter.default List
<MessageEmbed> The configured message embeds, this is the opposite ofMessageRequest.setEmbeds(Collection)
and only returns what was set using that setter.The IDs for roles which are allowed to be mentioned, or an empty list.The IDs for users which are allowed to be mentioned, or an empty list.default boolean
Whether this message would mention a user, if it is sent as a reply.default boolean
Whether embeds will be suppressed on this message.default boolean
Whether this message is using components V2.default R
mention
(Collection<? extends IMentionable> mentions) default R
mentionRepliedUser
(boolean mention) Whether to mention the user, when replying to a message.default R
mentionRoles
(Collection<String> roleIds) Used to provide a whitelist ofRoles
that should be pinged, even when they would not be pinged otherwise according to the Set of allowed mention types.default R
mentionUsers
(Collection<String> userIds) Used to provide a whitelist ofUsers
that should be pinged, even when they would not be pinged otherwise according to the Set of allowed mention types.default R
setAllowedMentions
(Collection<Message.MentionType> allowedMentions) Sets theMentionTypes
that should be parsed.default R
setComponents
(Collection<? extends MessageTopLevelComponent> components) TheMessageTopLevelComponents
that should be attached to the message.default R
setContent
(String content) The message content, which shows above embeds and attachments.default R
setEmbeds
(Collection<? extends MessageEmbed> embeds) TheMessageEmbeds
that should be attached to the message.default R
setFiles
(Collection<? extends FileUpload> files) TheFileUploads
that should be attached to the message.default R
setSuppressEmbeds
(boolean suppress) Set whether embeds should be suppressed on this message.default R
useComponentsV2
(boolean use) Sets whether this message is allowed to use V2 components, this is disabled by default.Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getComponentTree
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
applyMessage, mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers, setComponents, setComponents, setEmbeds, setFiles, useComponentsV2
-
Method Details
-
getBuilder
B getBuilder() -
setContent
Description copied from interface:MessageRequest
The message content, which shows above embeds and attachments.- Specified by:
setContent
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
content
- The content (up to 2000 characters)- Returns:
- The same instance for chaining
-
getContent
Description copied from interface:MessageData
The configured message content, this is the opposite forMessageRequest.setContent(String)
and only returns what was set using that setter.For message edit requests, this will not be the current content of the message.
- Specified by:
getContent
in interfaceMessageData
- Returns:
- The currently configured content, or an empty string if none was set yet
- See Also:
-
setEmbeds
Description copied from interface:MessageRequest
TheMessageEmbeds
that should be attached to the message.
You can useCollections.emptyList()
to remove all embeds from the message.This requires
Permission.MESSAGE_EMBED_LINKS
in the channel.- Specified by:
setEmbeds
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
embeds
- The embeds to attach to the message (up to 10)- Returns:
- The same instance for chaining
- See Also:
-
getEmbeds
Description copied from interface:MessageData
The configured message embeds, this is the opposite ofMessageRequest.setEmbeds(Collection)
and only returns what was set using that setter.For message edit requests, this will not be the current embeds of the message.
- Specified by:
getEmbeds
in interfaceMessageData
- Returns:
- The currently configured embeds, or an empty list if none were set yet
- See Also:
-
setComponents
@Nonnull default R setComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:MessageRequest
TheMessageTopLevelComponents
that should be attached to the message.
You can useCollections.emptyList()
to remove all components from the message.Example: Set 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") .setComponents(list) .queue();
Example: Remove action rows
channel.sendMessage("Content here") .setComponents(Collections.emptyList()) .queue();
- Specified by:
setComponents
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
components
- TheMessageTopLevelComponents
to set, can be empty to remove components, 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
-
useComponentsV2
Description copied from interface:MessageRequest
Sets whether this message is allowed to use V2 components, this is disabled by default.Using V2 components removes the top-level component limit, and allows more components in total (40).
They also allow you to use a larger choice of components, such as any component extendingMessageTopLevelComponent
, as long as they are compatible.
The character limit for the messages also gets changed to 4000.This, however, comes with a few drawbacks:
- You cannot send content, embeds, polls or stickers
- It does not support voice messages
- It does not support previewing files
- URLs don't create embeds
- You cannot switch this message back to not using Components V2 (you can however upgrade a message to V2)
A default value can be set in
MessageRequest.setDefaultUseComponentsV2(boolean)
.- Specified by:
useComponentsV2
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
use
-true
to enable V2 components,false
to disabled them.- Returns:
- The same instance for chaining
- See Also:
-
getComponents
Description copied from interface:MessageData
The configured message components, this is the opposite ofMessageRequest.setComponents(Collection)
and only returns what was set using that setter.For message edit requests, this will not be the current components of the message.
- Specified by:
getComponents
in interfaceMessageData
- Returns:
- The currently configured components, or an empty list if none were set yet
- See Also:
-
isUsingComponentsV2
default boolean isUsingComponentsV2()Description copied from interface:MessageData
Whether this message is using components V2.- Specified by:
isUsingComponentsV2
in interfaceMessageData
- Returns:
true
if this is using components V2- See Also:
-
setSuppressEmbeds
Description copied from interface:MessageRequest
Set whether embeds should be suppressed on this message.
This also includes rich embeds added viaMessageRequest.setEmbeds(MessageEmbed...)
.Default: false
- Specified by:
setSuppressEmbeds
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
suppress
- True, if all embeds should be suppressed- Returns:
- The same instance for chaining
-
isSuppressEmbeds
default boolean isSuppressEmbeds()Description copied from interface:MessageData
Whether embeds will be suppressed on this message.- Specified by:
isSuppressEmbeds
in interfaceMessageData
- Returns:
- True, if embeds are suppressed
-
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 interfaceMessageRequest<R extends MessageRequest<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 interfaceMessageData
- Returns:
- The currently configured attachments, or an empty list if none were set yet
- See Also:
-
mentionRepliedUser
Description copied from interface:MessageRequest
Whether to mention the user, when replying to a message.
This only matters in combination withMessageCreateAction.setMessageReference(...)
!This is true by default but can be configured using
MessageRequest.setDefaultMentionRepliedUser(boolean)
!- Specified by:
mentionRepliedUser
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
mention
- True, to mention the author in the referenced message- Returns:
- The same instance for chaining
-
setAllowedMentions
Description copied from interface:MessageRequest
Sets theMentionTypes
that should be parsed.
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
null
is provided to this method, then all Types will be mentionable (unless whitelisting via one of themention*
methods is used).Note: A default for this can be set using
AllowedMentions.setDefaultMentions(Collection)
.- Specified by:
setAllowedMentions
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
allowedMentions
- MentionTypes that are allowed to being parsed and mentioned. All other mention types will not be mentioned by this message. You can passnull
orEnumSet.allOf(MentionType.class)
to allow all mentions.- Returns:
- The same instance for chaining
-
mention
Description copied from interface:MessageRequest
Used to provide a whitelist forUsers
,Members
andRoles
that should be pinged, even when they would not be pinged otherwise according to the Set of allowed mention types.
On other types ofIMentionable
, this does nothing.Note: When a User/Member is whitelisted this way, then parsing of User mentions is automatically disabled (same applies to Roles).
Also note that whitelisting users or roles implicitly disables parsing of other mentions, if not otherwise set viaMessageRequest.setDefaultMentions(Collection)
orMessageRequest.setAllowedMentions(Collection)
.- Specified by:
mention
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
mentions
- Users, Members and Roles that should be explicitly whitelisted to be pingable.- Returns:
- The same instance for chaining
- See Also:
-
mentionUsers
Description copied from interface:MessageRequest
Used to provide a whitelist ofUsers
that should be pinged, even when they would not be pinged otherwise according to the Set of allowed mention types.Note: When a User is whitelisted this way, then parsing of User mentions is automatically disabled.
Also note that whitelisting users or roles implicitly disables parsing of other mentions, if not otherwise set viaMessageRequest.setDefaultMentions(Collection)
orMessageRequest.setAllowedMentions(Collection)
.- Specified by:
mentionUsers
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
userIds
- Ids of Users that should be explicitly whitelisted to be pingable.- Returns:
- The same instance for chaining
- See Also:
-
mentionRoles
Description copied from interface:MessageRequest
Used to provide a whitelist ofRoles
that should be pinged, even when they would not be pinged otherwise according to the Set of allowed mention types.Note: When a Role is whitelisted this way, then parsing of Role mentions is automatically disabled.
Also note that whitelisting users or roles implicitly disables parsing of other mentions, if not otherwise set viaMessageRequest.setDefaultMentions(Collection)
orMessageRequest.setAllowedMentions(Collection)
.- Specified by:
mentionRoles
in interfaceMessageRequest<R extends MessageRequest<R>>
- Parameters:
roleIds
- Ids of Roles that should be explicitly whitelisted to be pingable.- Returns:
- The same instance for chaining
- See Also:
-
getMentionedUsers
Description copied from interface:MessageData
The IDs for users which are allowed to be mentioned, or an empty list.- Specified by:
getMentionedUsers
in interfaceMessageData
- Returns:
- The user IDs which are mention whitelisted
-
getMentionedRoles
Description copied from interface:MessageData
The IDs for roles which are allowed to be mentioned, or an empty list.- Specified by:
getMentionedRoles
in interfaceMessageData
- Returns:
- The role IDs which are mention whitelisted
-
getAllowedMentions
Description copied from interface:MessageData
The mention types which are whitelisted.- Specified by:
getAllowedMentions
in interfaceMessageData
- Returns:
- The mention types which can be mentioned by this message
-
isMentionRepliedUser
default boolean isMentionRepliedUser()Description copied from interface:MessageData
Whether this message would mention a user, if it is sent as a reply.- Specified by:
isMentionRepliedUser
in interfaceMessageData
- Returns:
- True, if this would mention with the reply
-