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.abstract boolean
isValid()
Whether this builder has a valid state to build.mention
(Collection<? extends IMentionable> mentions) mentionRepliedUser
(boolean mention) Whether to mention the used, 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 LayoutComponent> components) TheLayoutComponents
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.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
Methods inherited from interface net.dv8tion.jda.api.utils.messages.MessageRequest
applyMessage, mention, mentionRoles, mentionRoles, mentionUsers, mentionUsers, setActionRow, setActionRow, setComponents, setEmbeds, setFiles, setFiles
-
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 used, 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 if 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
TheLayoutComponents
that should be attached to the message.
You can useCollections.emptyList()
to remove all components from the message.The most commonly used layout is
ActionRow
.Example: Set action rows
final List<LayoutComponent> 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 is still required") .setComponents(list) .queue();
Example: Remove action rows
channel.sendMessage("Content is still required") .setComponents(Collections.emptyList()) .queue();
- Specified by:
setComponents
in interfaceMessageRequest<T>
- Parameters:
components
- The components for the message (up to 5)- Returns:
- The same instance for chaining
-
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:
-
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
- If more than 5 component layouts are set
MessageEditBuilder
- 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
-