Class Message
- All Implemented Interfaces:
DiscordObject
,Entity
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describes extra features of a message.static enum
Represents the various types of messages. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The maximum amount of characters that can be in the contents of a message.static final int
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
ConstructorDescriptionMessage
(GatewayDiscordClient gateway, discord4j.discordjson.json.MessageData data) Constructs aMessage
with an associatedGatewayDiscordClient
and Discord data. -
Method Summary
Modifier and TypeMethodDescriptionaddReaction
(ReactionEmoji emoji) Requests to add a reaction on this message.delete()
Requests to delete this message.Requests to delete this message while optionally specifying a reason.discord4j.core.spec.MessageEditMono
edit()
Requests to edit this message.edit
(discord4j.core.spec.MessageEditSpec spec) Requests to edit this message.edit
(Consumer<? super LegacyMessageEditSpec> spec) Deprecated.boolean
Gets any attached files, with the same order as in the message.Gets the author of this message, if present.Requests to retrieve the author of this message as amember
of the guild in which it was sent.Requests to retrieve the channel the message was sent in.getChannel
(EntityRetrievalStrategy retrievalStrategy) Requests to retrieve the channel the message was sent in, using the given retrieval strategy.Gets the ID of the channel the message was sent in.Returns theGatewayDiscordClient
that created this object.Gets the components on the message.Gets the contents of the message, if present.discord4j.discordjson.json.MessageData
getData()
Gets the data of the message.Gets when this message was edited, if present.Gets any embedded content.getFlags()
Returns the flags of thisMessage
, describing its features.getGuild()
Requests to retrieve the guild this message is associated to, if present.getGuild
(EntityRetrievalStrategy retrievalStrategy) Requests to retrieve the guild this message is associated to, if present, using the given retrieval strategy.Gets the ID of the guild this message is associated to, if thisMessage
was built from Gateway data, like an incoming event.getId()
Gets the Snowflake that uniquely identifies this entity.Gets the interaction data, if the message is a response to anInteractions
.Gets the partial members specifically mentioned in this message, without duplication and with the same order as in the message.Returns theMessageReference
sent with crossposted messages and replies, if present.Gets the reactions to this message, the order is the same as in the message.getReactors
(ReactionEmoji emoji) Requests to retrieve the reactors (users) for the specified emoji for this message.Returns the message associated with theMessageReference
, if present.Gets the IDs of the roles specifically mentioned in this message, without duplication and with the same order as in the message.Requests to retrieve the roles specifically mentioned in this message.getRoleMentions
(EntityRetrievalStrategy retrievalStrategy) Requests to retrieve the roles specifically mentioned in this message, using the given retrieval strategy.Deprecated.Gets the partial stickers sent with the message.Gets when this message was sent.getType()
Gets the type of message.discord4j.discordjson.json.UserData
Gets the raw author data of this message.Gets the IDs of the users specifically mentioned in this message, without duplication and with the same order as in the message.Gets the users specifically mentioned in this message, without duplication and with the same order as in the message.Requests to retrieve the webhook that generated this message, if present.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
Gets whether this message mentions everyone.pin()
Requests to pin this message.publish()
Requests to publish (crosspost) this message if thechannel
is of type 'news'.Requests to remove all the reactions on this message.removeReaction
(ReactionEmoji emoji, Snowflake userId) Requests to remove a reaction from a specified user on this message.removeReactions
(ReactionEmoji emoji) Requests to remove all reactions of a specific emoji on this message.removeSelfReaction
(ReactionEmoji emoji) Requests to remove a reaction from the current user on this message.startThread
(discord4j.core.spec.StartThreadSpec spec) Creates a new thread from an existing message.suppressEmbeds
(boolean suppress) Requests to suppress all embeds in this message.toString()
unpin()
Requests to unpin this message.
-
Field Details
-
MAX_CONTENT_LENGTH
public static final int MAX_CONTENT_LENGTHThe maximum amount of characters that can be in the contents of a message.- See Also:
-
MAX_TOTAL_EMBEDS_CHARACTER_LENGTH
public static final int MAX_TOTAL_EMBEDS_CHARACTER_LENGTHThe 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:
-
-
Constructor Details
-
Message
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 Details
-
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
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
- Returns:
- A
RestMessage
handle to execute REST API operations on this entity.
-
getRestChannel
- Returns:
- A
RestChannel
handle to execute REST API operations on the channel of this message.
-
getChannelId
Gets the ID of the channel the message was sent in.- Returns:
- The ID of the channel the message was sent in.
-
getChannel
Requests to retrieve the channel the message was sent in. -
getChannel
Requests to retrieve the channel the message was sent in, using the given retrieval strategy. -
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
Gets the author of this message, if present.- Returns:
- The author of this message, if present.
-
getAuthorAsMember
Requests to retrieve the author of this message as amember
of the guild in which it was sent. -
getUserData
Gets the raw author data of this message.- Returns:
- The raw author data of this message.
-
getContent
Gets the contents of the message, if present.- Returns:
- The contents of the message, if present.
-
getTimestamp
Gets when this message was sent.- Returns:
- When this message was sent.
-
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
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
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
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
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
Requests to retrieve the roles specifically mentioned in this message. -
getRoleMentions
Requests to retrieve the roles specifically mentioned in this message, using the given retrieval strategy. -
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.
-
getEmbeds
Gets any embedded content.- Returns:
- Any embedded content.
-
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
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
Requests to retrieve the webhook that generated this message, if present. -
getMessageReference
Returns theMessageReference
sent with crossposted messages and replies, if present.- Returns:
- The
MessageReference
sent with crossposted messages and replies, if present.
-
getFlags
Returns the flags of thisMessage
, describing its features.- Returns:
- A
EnumSet
with the flags of this message.
-
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
Requests to retrieve the guild this message is associated to, if present. -
getGuild
Requests to retrieve the guild this message is associated to, if present, using the given retrieval strategy. -
getType
Gets the type of message.- Returns:
- The type of message.
-
getStickersItems
Gets the partial stickers sent with the message.- Returns:
- The partial stickers sent with the message.
-
getStickers
Deprecated.Gets the stickers sent with the message.- Returns:
- The stickers sent with the message.
-
getReferencedMessage
Returns the message associated with theMessageReference
, if present.- Returns:
- The message associated with the
MessageReference
, if present.
-
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
Gets the components on the message.- Returns:
- The components on the message.
-
edit
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
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:
-
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
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
Requests 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
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
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
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
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
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
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
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
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. -
startThread
Creates a new thread from an existing message.- Parameters:
spec
- an immutable object that specifies how to create the thread- Returns:
- A
Mono
where, upon successful completion, emits the createdThreadChannel
. If an error is received, it is emitted through theMono
.
-
equals
-
hashCode
public int hashCode() -
toString
-
edit(MessageEditSpec)
oredit()
which offer an immutable approach to build specs