Class AbstractMessageBuilder<T,R extends AbstractMessageBuilder<T,R>>
- Type Parameters:
T
- The result type used forbuild()
R
- The return type used for method chaining
- All Implemented Interfaces:
MessageData
,MessageRequest<R>
- Direct Known Subclasses:
MessageCreateBuilder
,MessageEditBuilder
MessageRequest
.
This builder cannot be instantiated directly. You should use MessageCreateBuilder
or MessageEditBuilder
instead.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionabstract T
build()
Builds a validated instance of this builder's state, which can then be used for requests.clear()
Clears this builder's state, resetting it to the initial state identical to creating a new instance.abstract R
Closes and removes allFileUploads
added to this builder.The mention types which are whitelisted.The configured message components, this is the opposite ofMessageRequest.setComponents(Collection)
and only returns what was set using that setter.The configured message content, this is the opposite forMessageRequest.setContent(String)
and only returns what was set using that setter.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.long
The flags set on this message.abstract boolean
isEmpty()
Whether this builder is considered empty, this checks for all required fields of the request type.boolean
Whether this message would mention a user, if it is sent as a reply.boolean
Whether embeds will be suppressed on this message.boolean
Whether this message is using components V2.abstract boolean
isValid()
Whether this builder has a valid state to build.mention
(Collection<? extends IMentionable> mentions) mentionRepliedUser
(boolean mention) Whether to mention the user, when replying to a message.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.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.setAllowedMentions
(Collection<Message.MentionType> allowedMentions) Sets theMentionTypes
that should be parsed.setComponents
(Collection<? extends MessageTopLevelComponent> components) TheMessageTopLevelComponents
that should be attached to the message.setContent
(String content) The message content, which shows above embeds and attachments.setEmbeds
(Collection<? extends MessageEmbed> embeds) TheMessageEmbeds
that should be attached to the message.setSuppressEmbeds
(boolean suppress) Set whether embeds should be suppressed on this message.useComponentsV2
(boolean use) Sets whether this message is allowed to use V2 components, this is disabled by default.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getAttachments, getComponentTree
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
applyMessage, mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers, setComponents, setComponents, setEmbeds, setFiles, setFiles, useComponentsV2
-
Method Details
-
setContent
Description copied from interface:MessageRequest
The message content, which shows above embeds and attachments.- Specified by:
setContent
in interfaceMessageRequest<T>
- 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:
-
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<T>
- 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<T>
- 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<T>
- 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<T>
- 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<T>
- 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
public 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
-
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<T>
- 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
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<T>
- 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<T>
- 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
public 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<T>
- Parameters:
suppress
- True, if all embeds should be suppressed- Returns:
- The same instance for chaining
-
isSuppressEmbeds
public 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
-
getMessageFlagsRaw
public long getMessageFlagsRaw()The flags set on this message.- Returns:
- The currently set message flags
-
isEmpty
public abstract boolean isEmpty()Whether this builder is considered empty, this checks for all required fields of the request type.
On a create request, this checks forcontent
,embeds
,components
, andfiles
.
An edit request is only considered empty if no setters were called. And never empty, if the builder is areplace request
.- Returns:
- True, if the builder state is empty
-
isValid
public abstract boolean isValid()Whether this builder has a valid state to build.
If this isfalse
, thenbuild()
throws anIllegalStateException
. You can check the exception docs onbuild()
for specifics.- Returns:
- True, if the builder is in a valid state
-
build
Builds a validated instance of this builder's state, which can then be used for requests.- Returns:
- The validated data instance
- Throws:
IllegalStateException
- ForMessageCreateBuilder
- If the builder is
empty
- If the content set is longer than 2000
- If more than 10 embeds are set
- When using components V1, if more than 5 top-level components are set
- When using components V2, if more than 40 total components are set
MessageEditBuilder
- If the content set is longer than 2000
- If more than 10 embeds are set
- When using components V1, if more than 5 top-level components are set
- When using components V2, if more than 40 total components are set
- If the builder is
-
clear
Clears this builder's state, resetting it to the initial state identical to creating a new instance.WARNING: This will remove all the files added to the builder, but will not close them. You can use
closeFiles()
before callingclear()
to close the files explicitly.- Returns:
- The same builder instance for chaining
-
closeFiles
Closes and removes allFileUploads
added to this builder.This will keep any
AttachmentUpdates
added to this builder, as those do not require closing. You can useMessageEditRequest.setAttachments(AttachedFile...)
to remove them as well.- Returns:
- The same builder instance for chaining
-