Class Message
- java.lang.Object
-
- discord4j.core.object.entity.Message
-
- All Implemented Interfaces:
DiscordObject
,Entity
public final class Message extends Object implements Entity
A Discord message.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Message.Flag
Describes extra features of a message.static class
Message.Type
Represents the various types of messages.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_CONTENT_LENGTH
The maximum amount of characters that can be in the contents of a message.static int
MAX_TOTAL_EMBEDS_CHARACTER_LENGTH
The maximum amount of characters that can be present when combining all title, description, field.name, field.value, footer.text, and author.name fields of all embeds for this message.
-
Constructor Summary
Constructors Constructor Description Message(GatewayDiscordClient gateway, discord4j.discordjson.json.MessageData data)
Constructs aMessage
with an associatedGatewayDiscordClient
and Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Mono<Void>
addReaction(ReactionEmoji emoji)
Requests to add a reaction on this message.Mono<Void>
delete()
Requests to delete this message.Mono<Void>
delete(String reason)
Requests to delete this message while optionally specifying a reason.discord4j.core.spec.MessageEditMono
edit()
Requests to edit this message.Mono<Message>
edit(discord4j.core.spec.MessageEditSpec spec)
Requests to edit this message.Mono<Message>
edit(Consumer<? super LegacyMessageEditSpec> spec)
Deprecated.useedit(MessageEditSpec)
oredit()
which offer an immutable approach to build specsboolean
equals(Object obj)
List<Attachment>
getAttachments()
Gets any attached files, with the same order as in the message.Optional<User>
getAuthor()
Gets the author of this message, if present.Mono<Member>
getAuthorAsMember()
Requests to retrieve the author of this message as amember
of the guild in which it was sent.Mono<MessageChannel>
getChannel()
Requests to retrieve the channel the message was sent in.Mono<MessageChannel>
getChannel(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the channel the message was sent in, using the given retrieval strategy.Snowflake
getChannelId()
Gets the ID of the channel the message was sent in.GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.List<LayoutComponent>
getComponents()
Gets the components on the message.String
getContent()
Gets the contents of the message, if present.discord4j.discordjson.json.MessageData
getData()
Gets the data of the message.Optional<Instant>
getEditedTimestamp()
Gets when this message was edited, if present.List<Embed>
getEmbeds()
Gets any embedded content.EnumSet<Message.Flag>
getFlags()
Returns the flags of thisMessage
, describing its features.Mono<Guild>
getGuild()
Requests to retrieve the guild this message is associated to, if present.Mono<Guild>
getGuild(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the guild this message is associated to, if present, using the given retrieval strategy.Optional<Snowflake>
getGuildId()
Gets the ID of the guild this message is associated to, if thisMessage
was built from Gateway data, like an incoming event.Snowflake
getId()
Gets the Snowflake that uniquely identifies this entity.Optional<MessageInteraction>
getInteraction()
Gets the interaction data, if the message is a response to anInteractions
.List<PartialMember>
getMemberMentions()
Gets the partial members specifically mentioned in this message, without duplication and with the same order as in the message.Optional<MessageReference>
getMessageReference()
Returns theMessageReference
sent with crossposted messages and replies, if present.List<Reaction>
getReactions()
Gets the reactions to this message, the order is the same as in the message.Flux<User>
getReactors(ReactionEmoji emoji)
Requests to retrieve the reactors (users) for the specified emoji for this message.Optional<Message>
getReferencedMessage()
Returns the message associated with theMessageReference
, if present.RestChannel
getRestChannel()
RestMessage
getRestMessage()
List<Snowflake>
getRoleMentionIds()
Gets the IDs of the roles specifically mentioned in this message, without duplication and with the same order as in the message.Flux<Role>
getRoleMentions()
Requests to retrieve the roles specifically mentioned in this message.Flux<Role>
getRoleMentions(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the roles specifically mentioned in this message, using the given retrieval strategy.List<Sticker>
getStickers()
Deprecated.List<PartialSticker>
getStickersItems()
Gets the partial stickers sent with the message.Instant
getTimestamp()
Gets when this message was sent.Message.Type
getType()
Gets the type of message.discord4j.discordjson.json.UserData
getUserData()
Gets the raw author data of this message.List<Snowflake>
getUserMentionIds()
Gets the IDs of the users specifically mentioned in this message, without duplication and with the same order as in the message.List<User>
getUserMentions()
Gets the users specifically mentioned in this message, without duplication and with the same order as in the message.Mono<Webhook>
getWebhook()
Requests to retrieve the webhook that generated this message, if present.Optional<Snowflake>
getWebhookId()
Gets the ID the webhook that generated this message, if present.int
hashCode()
boolean
isPinned()
Gets whether this message is pinned.boolean
isTts()
Gets whether this was a TTS (Text-To-Speech) message.boolean
mentionsEveryone()
Gets whether this message mentions everyone.Mono<Void>
pin()
Requests to pin this message.Mono<Message>
publish()
Requests to publish (crosspost) this message if thechannel
is of type 'news'.Mono<Void>
removeAllReactions()
Requests to remove all the reactions on this message.Mono<Void>
removeReaction(ReactionEmoji emoji, Snowflake userId)
Requests to remove a reaction from a specified user on this message.Mono<Void>
removeReactions(ReactionEmoji emoji)
Requests to remove all reactions of a specific emoji on this message.Mono<Void>
removeSelfReaction(ReactionEmoji emoji)
Requests to remove a reaction from the current user on this message.Mono<Void>
suppressEmbeds(boolean suppress)
Deprecated.- As of April 28, 2021, Discord removed the suppress-embeds route in API v9.String
toString()
Mono<Void>
unpin()
Requests to unpin this message.
-
-
-
Field Detail
-
MAX_CONTENT_LENGTH
public static final int MAX_CONTENT_LENGTH
The maximum amount of characters that can be in the contents of a message.- See Also:
- Constant Field Values
-
MAX_TOTAL_EMBEDS_CHARACTER_LENGTH
public static final int MAX_TOTAL_EMBEDS_CHARACTER_LENGTH
The maximum amount of characters that can be present when combining all title, description, field.name, field.value, footer.text, and author.name fields of all embeds for this message.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Message
public Message(GatewayDiscordClient gateway, discord4j.discordjson.json.MessageData data)
Constructs aMessage
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated to this object, must be non-null.data
- The raw data as represented by Discord, must be non-null.
-
-
Method Detail
-
getClient
public GatewayDiscordClient getClient()
Description copied from interface:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated to this object.
-
getId
public Snowflake getId()
Description copied from interface:Entity
Gets the Snowflake that uniquely identifies this entity.
-
getData
public discord4j.discordjson.json.MessageData getData()
Gets the data of the message.- Returns:
- The data of the message.
-
getRestMessage
public RestMessage getRestMessage()
- Returns:
- A
RestMessage
handle to execute REST API operations on this entity.
-
getRestChannel
public RestChannel getRestChannel()
- Returns:
- A
RestChannel
handle to execute REST API operations on the channel of this message.
-
getChannelId
public Snowflake getChannelId()
Gets the ID of the channel the message was sent in.- Returns:
- The ID of the channel the message was sent in.
-
getChannel
public Mono<MessageChannel> getChannel()
Requests to retrieve the channel the message was sent in.
-
getChannel
public Mono<MessageChannel> getChannel(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the channel the message was sent in, using the given retrieval strategy.
-
getWebhookId
public Optional<Snowflake> getWebhookId()
Gets the ID the webhook that generated this message, if present.- Returns:
- The ID of the webhook that generated this message, if present.
-
getAuthor
public Optional<User> getAuthor()
Gets the author of this message, if present.- Returns:
- The author of this message, if present.
-
getAuthorAsMember
public Mono<Member> getAuthorAsMember()
Requests to retrieve the author of this message as amember
of the guild in which it was sent.
-
getUserData
@Experimental public discord4j.discordjson.json.UserData getUserData()
Gets the raw author data of this message.- Returns:
- The raw author data of this message.
-
getContent
public String getContent()
Gets the contents of the message, if present.- Returns:
- The contents of the message, if present.
-
getTimestamp
public Instant getTimestamp()
Gets when this message was sent.- Returns:
- When this message was sent.
-
getEditedTimestamp
public Optional<Instant> getEditedTimestamp()
Gets when this message was edited, if present.- Returns:
- When this message was edited, if present.
-
isTts
public boolean isTts()
Gets whether this was a TTS (Text-To-Speech) message.- Returns:
true
if this message was a TTS (Text-To-Speech) message,false
otherwise.
-
mentionsEveryone
public boolean mentionsEveryone()
Gets whether this message mentions everyone.- Returns:
true
if this message mentions everyone,false
otherwise.
-
getUserMentionIds
public List<Snowflake> getUserMentionIds()
Gets the IDs of the users specifically mentioned in this message, without duplication and with the same order as in the message.- Returns:
- The IDs of the users specifically mentioned in this message, without duplication and with the same order as in the message.
-
getMemberMentions
public List<PartialMember> getMemberMentions()
Gets the partial members specifically mentioned in this message, without duplication and with the same order as in the message.- Returns:
- The partial members specifically mentioned in this message, without duplication and with the same order as in the message.
-
getUserMentions
public List<User> getUserMentions()
Gets the users specifically mentioned in this message, without duplication and with the same order as in the message.- Returns:
- The users specifically mentioned in this message, without duplication and with the same order as in the message.
-
getRoleMentionIds
public List<Snowflake> getRoleMentionIds()
Gets the IDs of the roles specifically mentioned in this message, without duplication and with the same order as in the message.- Returns:
- The IDs of the roles specifically mentioned in this message, without duplication and with the same order as in the message.
-
getRoleMentions
public Flux<Role> getRoleMentions()
Requests to retrieve the roles specifically mentioned in this message.
-
getRoleMentions
public Flux<Role> getRoleMentions(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the roles specifically mentioned in this message, using the given retrieval strategy.
-
getAttachments
public List<Attachment> getAttachments()
Gets any attached files, with the same order as in the message.- Returns:
- Any attached files, with the same order as in the message.
-
getReactions
public List<Reaction> getReactions()
Gets the reactions to this message, the order is the same as in the message.- Returns:
- The reactions to this message, the order is the same as in the message.
-
getReactors
public Flux<User> getReactors(ReactionEmoji emoji)
Requests to retrieve the reactors (users) for the specified emoji for this message.
-
isPinned
public boolean isPinned()
Gets whether this message is pinned.- Returns:
true
if this message is pinned,false
otherwise.
-
getWebhook
public Mono<Webhook> getWebhook()
Requests to retrieve the webhook that generated this message, if present.
-
getMessageReference
public Optional<MessageReference> getMessageReference()
Returns theMessageReference
sent with crossposted messages and replies, if present.- Returns:
- The
MessageReference
sent with crossposted messages and replies, if present.
-
getFlags
public EnumSet<Message.Flag> getFlags()
Returns the flags of thisMessage
, describing its features.- Returns:
- A
EnumSet
with the flags of this message.
-
getGuildId
public Optional<Snowflake> getGuildId()
Gets the ID of the guild this message is associated to, if thisMessage
was built from Gateway data, like an incoming event. If requested from REST API, this field will be empty.- Returns:
- The ID of the guild this message is associated to, if present.
-
getGuild
public Mono<Guild> getGuild()
Requests to retrieve the guild this message is associated to, if present.
-
getGuild
public Mono<Guild> getGuild(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the guild this message is associated to, if present, using the given retrieval strategy.
-
getType
public Message.Type getType()
Gets the type of message.- Returns:
- The type of message.
-
getStickersItems
@Experimental public List<PartialSticker> getStickersItems()
Gets the partial stickers sent with the message.- Returns:
- The partial stickers sent with the message.
-
getStickers
@Deprecated public List<Sticker> getStickers()
Deprecated.Gets the stickers sent with the message.- Returns:
- The stickers sent with the message.
-
getReferencedMessage
public Optional<Message> getReferencedMessage()
Returns the message associated with theMessageReference
, if present.- Returns:
- The message associated with the
MessageReference
, if present.
-
getInteraction
public Optional<MessageInteraction> getInteraction()
Gets the interaction data, if the message is a response to anInteractions
.- Returns:
- The interaction data, if the message is a response to an
Interactions
.
-
getComponents
public List<LayoutComponent> getComponents()
Gets the components on the message.- Returns:
- The components on the message.
-
edit
@Deprecated public Mono<Message> edit(Consumer<? super LegacyMessageEditSpec> spec)
Deprecated.useedit(MessageEditSpec)
oredit()
which offer an immutable approach to build specsRequests to edit this message.- Parameters:
spec
- AConsumer
that provides a "blank"LegacyMessageEditSpec
to be operated on.- Returns:
- A
Mono
where, upon successful completion, emits the editedMessage
. If an error is received, it is emitted through theMono
.
-
edit
public Mono<Message> edit(discord4j.core.spec.MessageEditSpec spec)
Requests to edit this message.To partially or completely replace attachments, see the docs for
edit()
for examples and adapt them to a standalone spec.
-
edit
public discord4j.core.spec.MessageEditMono edit()
Requests to edit this message. Properties specifying how to edit this message can be set via thewithXxx
methods of the returnedMessageEditMono
.By default, this method will append any file added through
withFiles
. To replace or remove individual attachments, usewithAttachments
along withAttachment
objects from the original message you want to keep. It is not required to include the new files asAttachment
objects.For example, to replace all previous attachments, provide an empty
withAttachments
and your files:message.edit() .withContentOrNull("Replaced all attachments") .withFiles(getFile()) .withComponents(row) .withAttachments();
To replace a specific attachment, you need to pass the attachment details you want to keep. You could work from the original
getAttachments()
list and pass it towithAttachments
and your files. The following example removes only the first attachment:message.edit() .withContentOrNull("Replaced the first attachment") .withFiles(getFile()) .withComponents(row) .withAttachmentsOrNull(message.getAttachments() .stream() .skip(1) .collect(Collectors.toList()));
To clear all attachments, provide an empty
withAttachments
:message.edit() .withContentOrNull("Removed all attachments") .withComponents(row) .withAttachments();
- Returns:
- A
MessageEditMono
where, upon successful completion, emits the editedMessage
. If an error is received, it is emitted through theMessageEditMono
. - See Also:
edit(MessageEditSpec)
-
delete
public Mono<Void> delete()
Requests to delete this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the message has been deleted. If an error is received, it is emitted through theMono
.
-
delete
public Mono<Void> delete(@Nullable String reason)
Requests to delete this message while optionally specifying a reason.- Parameters:
reason
- The reason, if present.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the message has been deleted. If an error is received, it is emitted through theMono
.
-
suppressEmbeds
@Deprecated public Mono<Void> suppressEmbeds(boolean suppress)
Deprecated.- As of April 28, 2021, Discord removed the suppress-embeds route in API v9. This method will be removed in a future update. https://discord.com/developers/docs/change-log#april-28-2021Requests to suppress all embeds in this message. If the message have the embeds suppressed then this action can undo the suppressed embeds.- Parameters:
suppress
- Determine if you need suppress or not the embeds.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the process has been completed. If an error is received, it is emitted through theMono
.
-
addReaction
public Mono<Void> addReaction(ReactionEmoji emoji)
Requests to add a reaction on this message.- Parameters:
emoji
- The reaction to add on this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the reaction was added on this message. If an error is received, it is emitted through theMono
.
-
removeReaction
public Mono<Void> removeReaction(ReactionEmoji emoji, Snowflake userId)
Requests to remove a reaction from a specified user on this message.- Parameters:
emoji
- The reaction to remove on this message.userId
- The user to remove the reaction on this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the reaction from the specified user was removed on this message. If an error is received, it is emitted through theMono
.
-
removeReactions
public Mono<Void> removeReactions(ReactionEmoji emoji)
Requests to remove all reactions of a specific emoji on this message.- Parameters:
emoji
- The reaction to remove on this message- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the reaction from the specified user was removed on this message. If an error is received, it is emitted through theMono
.
-
removeSelfReaction
public Mono<Void> removeSelfReaction(ReactionEmoji emoji)
Requests to remove a reaction from the current user on this message.- Parameters:
emoji
- The reaction to remove on this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the reaction from the current user was removed on this message. If an error is received, it is emitted through theMono
.
-
removeAllReactions
public Mono<Void> removeAllReactions()
Requests to remove all the reactions on this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating all the reactions on this message were removed. If an error is received, it is emitted through theMono
.
-
pin
public Mono<Void> pin()
Requests to pin this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the messaged was pinned. If an error is received, it is emitted through theMono
.
-
unpin
public Mono<Void> unpin()
Requests to unpin this message.- Returns:
- A
Mono
where, upon successful completion, emits nothing; indicating the message was unpinned. If an error is received, it is emitted through theMono
.
-
publish
public Mono<Message> publish()
Requests to publish (crosspost) this message if thechannel
is of type 'news'. Requires 'SEND_MESSAGES' permission if the current user sent the message, or additionally the 'MANAGE_MESSAGES' permission, for all other messages, to be present for the current user.
-
-