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 Tbuild()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 RCloses and removes allFileUploadsadded 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.longThe flags set on this message.abstract booleanisEmpty()Whether this builder is considered empty, this checks for all required fields of the request type.booleanWhether this message would mention a user, if it is sent as a reply.booleanWhether embeds will be suppressed on this message.abstract booleanisValid()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 ofRolesthat 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 ofUsersthat 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 theMentionTypesthat should be parsed.setComponents(Collection<? extends LayoutComponent> components) TheLayoutComponentsthat should be attached to the message.setContent(String content) The message content, which shows above embeds and attachments.setEmbeds(Collection<? extends MessageEmbed> embeds) TheMessageEmbedsthat 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, waitMethods inherited from interface net.dv8tion.jda.api.utils.messages.MessageData
getAttachmentsMethods 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:MessageRequestThe message content, which shows above embeds and attachments.- Specified by:
setContentin interfaceMessageRequest<T>- Parameters:
content- The content (up to 2000 characters)- Returns:
- The same instance for chaining
-
getContent
Description copied from interface:MessageDataThe 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:
getContentin interfaceMessageData- Returns:
- The currently configured content, or an empty string if none was set yet
- See Also:
-
mentionRepliedUser
Description copied from interface:MessageRequestWhether 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:
mentionRepliedUserin interfaceMessageRequest<T>- Parameters:
mention- True, to mention the author in the referenced message- Returns:
- The same instance for chaining
-
setAllowedMentions
Description copied from interface:MessageRequestSets theMentionTypesthat 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
nullis 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:
setAllowedMentionsin 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 passnullorEnumSet.allOf(MentionType.class)to allow all mentions.- Returns:
- The same instance for chaining
-
mention
Description copied from interface:MessageRequestUsed to provide a whitelist forUsers,MembersandRolesthat 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:
mentionin 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:MessageRequestUsed to provide a whitelist ofUsersthat 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:
mentionUsersin 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:MessageRequestUsed to provide a whitelist ofRolesthat 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:
mentionRolesin 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:MessageDataThe IDs for users which are allowed to be mentioned, or an empty list.- Specified by:
getMentionedUsersin interfaceMessageData- Returns:
- The user IDs which are mention whitelisted
-
getMentionedRoles
Description copied from interface:MessageDataThe IDs for roles which are allowed to be mentioned, or an empty list.- Specified by:
getMentionedRolesin interfaceMessageData- Returns:
- The role IDs which are mention whitelisted
-
getAllowedMentions
Description copied from interface:MessageDataThe mention types which are whitelisted.- Specified by:
getAllowedMentionsin interfaceMessageData- Returns:
- The mention types which can be mentioned by this message
-
isMentionRepliedUser
public boolean isMentionRepliedUser()Description copied from interface:MessageDataWhether this message would mention a user, if it is sent as a reply.- Specified by:
isMentionRepliedUserin interfaceMessageData- Returns:
- True, if this would mention with the reply
-
setEmbeds
Description copied from interface:MessageRequestTheMessageEmbedsthat should be attached to the message.
You can useCollections.emptyList()to remove all embeds from the message.This requires
Permission.MESSAGE_EMBED_LINKSin the channel.- Specified by:
setEmbedsin 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:MessageDataThe 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:
getEmbedsin interfaceMessageData- Returns:
- The currently configured embeds, or an empty list if none were set yet
- See Also:
-
setComponents
Description copied from interface:MessageRequestTheLayoutComponentsthat 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:
setComponentsin interfaceMessageRequest<T>- Parameters:
components- The components for the message (up to 5)- Returns:
- The same instance for chaining
-
getComponents
Description copied from interface:MessageDataThe 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:
getComponentsin interfaceMessageData- Returns:
- The currently configured components, or an empty list if none were set yet
- See Also:
-
setSuppressEmbeds
Description copied from interface:MessageRequestSet whether embeds should be suppressed on this message.
This also includes rich embeds added viaMessageRequest.setEmbeds(MessageEmbed...).Default: false
- Specified by:
setSuppressEmbedsin 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:MessageDataWhether embeds will be suppressed on this message.- Specified by:
isSuppressEmbedsin 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 allFileUploadsadded to this builder.This will keep any
AttachmentUpdatesadded 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
-