Class ReceivedMessage
- All Implemented Interfaces:
Formattable
,ISnowflake
,Message
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.entities.Message
Message.Attachment, Message.Interaction, Message.InteractionMetadata, Message.MentionType, Message.MessageFlag
-
Field Summary
FieldsFields inherited from interface net.dv8tion.jda.api.entities.Message
INVITE_PATTERN, JUMP_URL, JUMP_URL_PATTERN, MAX_COMPONENT_COUNT, MAX_COMPONENT_COUNT_IN_COMPONENT_TREE, MAX_CONTENT_LENGTH, MAX_CONTENT_LENGTH_COMPONENT_V2, MAX_EMBED_COUNT, MAX_FILE_AMOUNT, MAX_FILE_SIZE, MAX_NONCE_LENGTH, MAX_REACTIONS, MAX_STICKER_COUNT
-
Constructor Summary
ConstructorsConstructorDescriptionReceivedMessage
(long id, long channelId, long guildId, JDA jda, Guild guild, MessageChannel channel, MessageType type, MessageReference messageReference, boolean fromWebhook, long applicationId, boolean tts, boolean pinned, String content, String nonce, User author, Member member, MessageActivity activity, MessagePoll poll, OffsetDateTime editTime, Mentions mentions, List<MessageReaction> reactions, List<Message.Attachment> attachments, List<MessageEmbed> embeds, List<StickerItem> stickers, List<MessageTopLevelComponentUnion> components, List<MessageSnapshot> messageSnapshots, int flags, Message.Interaction interaction, Message.InteractionMetadata interactionMetadata, ThreadChannel startedThread, int position) -
Method Summary
Modifier and TypeMethodDescriptionaddReaction
(Emoji emoji) Adds a reaction to this Message using anEmoji
.Removes all reactions from this Message.clearReactions
(Emoji emoji) Removes all reactions for the specifiedEmoji
.createThreadChannel
(String name) Creates a new, publicThreadChannel
spawning/starting at thisMessage
inside theIThreadContainer
this message was sent in.Attempts to crosspost this message.delete()
Deletes this Message from Discord.editMessage
(CharSequence newContent) Edits this message and updates the content.editMessage
(MessageEditData newContent) Edits this message using the providedMessageEditData
.editMessageAttachments
(Collection<? extends AttachedFile> attachments) Edits this message using the provided files.editMessageComponents
(Collection<? extends MessageTopLevelComponent> components) Edits this message using the providedMessageTopLevelComponents
.editMessageEmbeds
(Collection<? extends MessageEmbed> embeds) Edits this message using the providedMessageEmbeds
.editMessageFormat
(String format, Object... args) Edits this message using the provided format arguments.endPoll()
End the poll attached to this message.boolean
void
AMessageActivity
that contains its type and party id.long
If this message is from an application-ownedWebhook
or is a response to anInteraction
, this will return the application's id.int
Returns the approximate position of this message in aThreadChannel
.An immutable list ofAttachments
that are attached to this message.The author of this MessageTheCategory
this message was sent in.Returns theMessageChannel
that this message was sent in.long
The ID for the channel this message was sent in.Gets theChannelType
that this message was received from.Layouts of interactive components, usuallyActionRows
.The textual content of this message in the format that would be shown to the Discord client.The raw textual content of this message.Gets the textual content of this message usingMessage.getContentDisplay()
and then strips it of markdown characters like *, **, __, ~~, || that provide text formatting.An immutable list ofMessageEmbeds
that are part of this Message.getFlags()
Returns an EnumSet of allMessageFlags
present for this Message.long
Returns the raw message flags of this messagegetGuild()
Returns theGuild
that this message was sent in.Returns theGuildMessageChannel
that this message was sent in if it was sent in a Guild.long
The ID for the guild this message was sent in.long
The Snowflake id of this entity.This is sent on the message object when the message is a response to anInteraction
without an existing message.Returns the interaction metadata, available when the message is a response or a followup to anInteraction
.Creates an immutable List ofInvite
codes that are included in this Message.getJDA()
Returns theJDA
instance related to this Message.Returns the jump-to URL for the received message.Returns the author of this Message as amember
.TheMentions
used in this message.Returns theMessageReference
for this Message.TheMessageSnaphots
attached to this message.getNonce()
Validation nonce for this Message
This can be used to validate that a Message was properly sent to the Discord Service.getPoll()
TheMessagePoll
attached to this message.getReaction
(Emoji emoji) This obtains theMessageReaction
for the givenEmoji
on this message.AllMessageReactions
that are on this Message.Returns a possiblynull
ThreadChannel
that was started from this message.AllStickerItems
that are in this Message.Provides theOffsetDateTime
defining when this Message was last edited.getType()
This specifies theMessageType
of this Message.boolean
Whether this message instance has an availableMessage.getChannel()
.boolean
hasGuild()
Whether this message instance provides a guild instance viaMessage.getGuild()
.int
hashCode()
boolean
isEdited()
Returns whether or not this Message has been edited before.boolean
Whether this message is ephemeral.boolean
Whether this message was sent in aGuild
.boolean
isFromType
(ChannelType type) Used to determine if this Message was received from aMessageChannel
of theChannelType
specified.boolean
isPinned()
Whether or not this Message has been pinned in its parent channel.boolean
Whether embeds are suppressed for this message.boolean
Whether this message is silent.boolean
isTTS()
Defines whether or not this Message triggers TTS (Text-To-Speech).boolean
Whether this message can contain V2 components.boolean
Whether this message is a voice message.boolean
pin()
Used to add the Message to theMessageChannel's
pinned message list.removeReaction
(Emoji emoji) Removes own reaction from this Message using anEmoji
, you can useMessage.removeReaction(Emoji, User)
to remove reactions from other users, orMessage.clearReactions(Emoji)
to remove all reactions for the specified emoji.removeReaction
(Emoji emoji, User user) retrieveReactionUsers
(Emoji emoji, MessageReaction.ReactionType type) suppressEmbeds
(boolean suppressed) Enables/Disables suppression of Embeds on this Message.toString()
unpin()
Used to remove the Message from theMessageChannel's
pinned message list.withHook
(WebhookClient<Message> hook) Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getTimeCreated
Methods inherited from interface net.dv8tion.jda.api.entities.Message
editMessageAttachments, editMessageComponents, editMessageComponents, editMessageEmbeds, forwardTo, getActionRows, getApplicationId, getButtonById, getButtons, getButtonsByLabel, getChannelId, getComponentTree, getGuildId, getReferencedMessage, reply, reply, replyComponents, replyComponents, replyComponents, replyEmbeds, replyEmbeds, replyFiles, replyFiles, replyFormat, replyPoll, replyStickers, replyStickers, retrievePollVoters, retrieveReactionUsers
-
Field Details
-
didContentIntentWarning
public static boolean didContentIntentWarning
-
-
Constructor Details
-
ReceivedMessage
public ReceivedMessage(long id, long channelId, long guildId, JDA jda, Guild guild, MessageChannel channel, MessageType type, MessageReference messageReference, boolean fromWebhook, long applicationId, boolean tts, boolean pinned, String content, String nonce, User author, Member member, MessageActivity activity, MessagePoll poll, OffsetDateTime editTime, Mentions mentions, List<MessageReaction> reactions, List<Message.Attachment> attachments, List<MessageEmbed> embeds, List<StickerItem> stickers, List<MessageTopLevelComponentUnion> components, List<MessageSnapshot> messageSnapshots, int flags, Message.Interaction interaction, Message.InteractionMetadata interactionMetadata, ThreadChannel startedThread, int position)
-
-
Method Details
-
withHook
-
getJDA
Description copied from interface:Message
Returns theJDA
instance related to this Message. -
getMessageReference
Description copied from interface:Message
Returns theMessageReference
for this Message. This will be null if this Message has no reference.This will have different meaning depending on the message
type
. The following are the message types where a reference will be present:INLINE_REPLY
THREAD_STARTER_MESSAGE
CONTEXT_COMMAND
(message context command)
You can access all the information about a reference through this object. Additionally, you can retrieve the referenced Message if discord did not load it in time. This can be done with
MessageReference.resolve()
.- Specified by:
getMessageReference
in interfaceMessage
- Returns:
- The message reference, or null.
-
isPinned
public boolean isPinned()Description copied from interface:Message
Whether or not this Message has been pinned in its parent channel. -
pin
Description copied from interface:Message
Used to add the Message to theMessageChannel's
pinned message list.
This is a shortcut method toMessageChannel.pinMessageById(String)
.The success or failure of this action will not affect the return of
Message.isPinned()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The pin request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked, or the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The pin request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
pin
in interfaceMessage
- Returns:
RestAction
- Type:Void
-
unpin
Description copied from interface:Message
Used to remove the Message from theMessageChannel's
pinned message list.
This is a shortcut method toMessageChannel.unpinMessageById(String)
.The success or failure of this action will not affect the return of
Message.isPinned()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The unpin request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked, or the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The unpin request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
unpin
in interfaceMessage
- Returns:
RestAction
- Type:Void
-
addReaction
Description copied from interface:Message
Adds a reaction to this Message using anEmoji
.This message instance will not be updated by this operation.
Reactions are the small emoji below a message that have a counter beside them showing how many users have reacted with the same emoji.
Neither success nor failure of this request will affect this Message's
Message.getReactions()
return as Message is immutable.The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
REACTION_BLOCKED
The user has blocked the currently logged in account and the reaction failedTOO_MANY_REACTIONS
The message already has too many reactions to proceedMISSING_PERMISSIONS
The reaction request was attempted after the account lostPermission.MESSAGE_ADD_REACTION
orPermission.MESSAGE_HISTORY
in theGuildChannel
when adding the reaction.UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
addReaction
in interfaceMessage
- Parameters:
emoji
- TheEmoji
to add as a reaction to this Message.- Returns:
RestAction
-
clearReactions
Description copied from interface:Message
Removes all reactions from this Message.
This is useful for moderator commands that wish to remove all reactions at once from a specific message.Please note that you can't clear reactions if this message was sent in a
PrivateChannel
!Neither success nor failure of this request will affect this Message's
Message.getReactions()
return as Message is immutable.The following
ErrorResponses
are possible:MISSING_ACCESS
The clear-reactions request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked, or the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The clear-reactions request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
when adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
clearReactions
in interfaceMessage
- Returns:
RestAction
-
clearReactions
Description copied from interface:Message
Removes all reactions for the specifiedEmoji
.Please note that you can't clear reactions if this message was sent in a
PrivateChannel
!The following
ErrorResponses
are possible:MISSING_ACCESS
The currently logged in account lost access to the channel by either being removed from the guild or losing theVIEW_CHANNEL
permissionUNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
clearReactions
in interfaceMessage
- Parameters:
emoji
- TheEmoji
to remove reactions for- Returns:
RestAction
-
removeReaction
Description copied from interface:Message
Removes own reaction from this Message using anEmoji
, you can useMessage.removeReaction(Emoji, User)
to remove reactions from other users, orMessage.clearReactions(Emoji)
to remove all reactions for the specified emoji.This message instance will not be updated by this operation.
Reactions are the small emojis below a message that have a counter beside them showing how many users have reacted with the same emoji.
Neither success nor failure of this request will affect this Message's
Message.getReactions()
return as Message is immutable.The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
removeReaction
in interfaceMessage
- Parameters:
emoji
- TheEmoji
reaction to remove as a reaction from this Message.- Returns:
RestAction
-
removeReaction
Description copied from interface:Message
Removes aUser's
reaction from this Message using anEmoji
.Please note that you can't remove reactions of other users if this message was sent in a
PrivateChannel
!This message instance will not be updated by this operation.
Reactions are the small emojis below a message that have a counter beside them showing how many users have reacted with the same emoji.
Neither success nor failure of this request will affect this Message's
Message.getReactions()
return as Message is immutable.The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
MISSING_PERMISSIONS
The reaction request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
when removing the reaction.UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
removeReaction
in interfaceMessage
- Parameters:
emoji
- TheEmoji
reaction to remove as a reaction from this Message.user
- TheUser
to remove the reaction for.- Returns:
RestAction
-
retrieveReactionUsers
@Nonnull public ReactionPaginationAction retrieveReactionUsers(@Nonnull Emoji emoji, @Nonnull MessageReaction.ReactionType type) Description copied from interface:Message
This obtains theusers
who reacted using the givenEmoji
.Messages maintain a list of reactions, alongside a list of users who added them.
Using this data, we can obtain a
ReactionPaginationAction
of the users who've reacted to this message.The following
ErrorResponses
are possible:MISSING_ACCESS
The retrieve request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emoji was deleted, doesn't exist, or is not available to the currently logged-in account in this channel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
retrieveReactionUsers
in interfaceMessage
- Parameters:
emoji
- TheEmoji
to retrieve users for.type
- The specific type of reaction- Returns:
- The
ReactionPaginationAction
of the users who reacted with the provided emoji
-
getReaction
Description copied from interface:Message
This obtains theMessageReaction
for the givenEmoji
on this message.
The reaction instance also store which users reacted with the specified emoji.Messages store reactions by keeping a list of reaction names.
- Specified by:
getReaction
in interfaceMessage
- Parameters:
emoji
- The unicode or custom emoji of the reaction emoji- Returns:
- The
MessageReaction
or null if not present.
-
getType
Description copied from interface:Message
This specifies theMessageType
of this Message.Messages can represent more than just simple text sent by Users, they can also be special messages that inform about events that occur. Messages can either be
default messages
or special messages likewelcome messages
.- Specified by:
getType
in interfaceMessage
- Returns:
- The
MessageType
of this message.
-
getInteraction
Description copied from interface:Message
This is sent on the message object when the message is a response to anInteraction
without an existing message.This means responses to Message Components do not include this property, instead including a message reference object as components always exist on preexisting messages.
- Specified by:
getInteraction
in interfaceMessage
- Returns:
- The
Interaction
of this message.
-
getInteractionMetadata
Description copied from interface:Message
Returns the interaction metadata, available when the message is a response or a followup to anInteraction
.- Specified by:
getInteractionMetadata
in interfaceMessage
- Returns:
- The
Message.InteractionMetadata
of this message, ornull
-
getIdLong
public long getIdLong()Description copied from interface:ISnowflake
The Snowflake id of this entity. This is unique to every entity and will never change.- Specified by:
getIdLong
in interfaceISnowflake
- Returns:
- Long containing the Id.
-
getJumpUrl
Description copied from interface:Message
Returns the jump-to URL for the received message. Clicking this URL in the Discord client will cause the client to jump to the specified message.- Specified by:
getJumpUrl
in interfaceMessage
- Returns:
- A String representing the jump-to URL for the message
-
isEdited
public boolean isEdited()Description copied from interface:Message
Returns whether or not this Message has been edited before. -
getTimeEdited
Description copied from interface:Message
Provides theOffsetDateTime
defining when this Message was last edited. If this Message has not been edited (Message.isEdited()
isfalse
), then this method will returnnull
.- Specified by:
getTimeEdited
in interfaceMessage
- Returns:
- Time of the most recent edit, or
null
if the Message has never been edited.
-
getAuthor
Description copied from interface:Message
The author of this Message -
getMember
Description copied from interface:Message
Returns the author of this Message as amember
.
This is only valid if the Message was actually sent in a GuildMessageChannel. This will returnnull
if the message was not sent in a GuildMessageChannel, or if the message was sent by a Webhook (including apps).
You can check the type of channel this message was sent from usingMessage.isFromType(ChannelType)
orMessage.getChannelType()
.Discord does not provide a member object for messages returned by
RestActions
of any kind. This will return null if the message was retrieved throughMessageChannel.retrieveMessageById(long)
or similar means, unless the member is already cached. -
getApproximatePosition
public int getApproximatePosition()Description copied from interface:Message
Returns the approximate position of this message in aThreadChannel
.
This can be used to estimate the relative position of a message in a thread, by comparing againstThreadChannel.getTotalMessageCount()
.Notes:
- The position might contain gaps or duplicates.
- The position is not set on messages sent earlier than July 19th, 2022, and will return -1.
- Specified by:
getApproximatePosition
in interfaceMessage
- Returns:
- The approximate position of this message, or
-1
if this message is too old. - See Also:
-
getContentStripped
Description copied from interface:Message
Gets the textual content of this message usingMessage.getContentDisplay()
and then strips it of markdown characters like *, **, __, ~~, || that provide text formatting. Any characters that match these but are not being used for formatting are escaped to prevent possible formatting.Requires
GatewayIntent.MESSAGE_CONTENT
- Specified by:
getContentStripped
in interfaceMessage
- Returns:
- The textual content from
Message.getContentDisplay()
with all text formatting characters removed or escaped.
-
getContentDisplay
Description copied from interface:Message
The textual content of this message in the format that would be shown to the Discord client. AllIMentionable
entities will be resolved to the format shown by the Discord client instead of the <id> format.This includes resolving:
Users
/Members
to their @Username/@Nickname format,GuildChannels
to their #ChannelName format,Roles
to their @RoleName formatCustom Emojis
(not unicode emojis!) to their:name:
format.If you want the actual Content (mentions as <@id>), use
Message.getContentRaw()
insteadRequires
GatewayIntent.MESSAGE_CONTENT
- Specified by:
getContentDisplay
in interfaceMessage
- Returns:
- The textual content of the message with mentions resolved to be visually like the Discord client.
-
getContentRaw
Description copied from interface:Message
The raw textual content of this message. Does not resolveIMentionable
entities likeMessage.getContentDisplay()
does. This means that this is the completely raw textual content of the message received from Discord and can contain mentions specified by Discord's Message Formatting.Requires
GatewayIntent.MESSAGE_CONTENT
- Specified by:
getContentRaw
in interfaceMessage
- Returns:
- The raw textual content of the message, containing unresolved Discord message formatting.
-
getInvites
Description copied from interface:Message
Creates an immutable List ofInvite
codes that are included in this Message.
This will use thePattern
provided underMessage.INVITE_PATTERN
to construct aMatcher
that will parse theMessage.getContentRaw()
output and include all codes it finds in a list.You can use the codes to retrieve/validate invites via
Invite.resolve(JDA, String)
- Specified by:
getInvites
in interfaceMessage
- Returns:
- Immutable list of invite codes
-
getNonce
Description copied from interface:Message
Validation nonce for this Message
This can be used to validate that a Message was properly sent to the Discord Service.
To set a nonce before sending you may useMessageCreateAction.setNonce(String)
! -
isFromType
Description copied from interface:Message
Used to determine if this Message was received from aMessageChannel
of theChannelType
specified.Useful for restricting functionality to a certain type of channels.
- Specified by:
isFromType
in interfaceMessage
- Parameters:
type
- TheChannelType
to check against.- Returns:
- True if the
ChannelType
which this message was received from is the same as the one specified bytype
.
-
isFromGuild
public boolean isFromGuild()Description copied from interface:Message
Whether this message was sent in aGuild
.
If this isfalse
thenMessage.getGuild()
will throw anIllegalStateException
.- Specified by:
isFromGuild
in interfaceMessage
- Returns:
- True, if
Message.getChannelType()
.isGuild()
is true.
-
getChannelType
Description copied from interface:Message
Gets theChannelType
that this message was received from.- Specified by:
getChannelType
in interfaceMessage
- Returns:
- The ChannelType which this message was received from.
-
getChannel
Description copied from interface:Message
Returns theMessageChannel
that this message was sent in.- Specified by:
getChannel
in interfaceMessage
- Returns:
- The MessageChannel of this Message
- See Also:
-
getGuildChannel
Description copied from interface:Message
Returns theGuildMessageChannel
that this message was sent in if it was sent in a Guild.- Specified by:
getGuildChannel
in interfaceMessage
- Returns:
- The MessageChannel of this Message
- See Also:
-
getCategory
Description copied from interface:Message
TheCategory
this message was sent in. This will always benull
for DMs.
Equivalent togetGuildChannel().getParentCategory()
if this was sent in aGuildMessageChannel
.- Specified by:
getCategory
in interfaceMessage
- Returns:
Category
for this message
-
hasGuild
public boolean hasGuild()Description copied from interface:Message
Whether this message instance provides a guild instance viaMessage.getGuild()
.
This is different fromMessage.isFromGuild()
, which checks whether the message was sent in a guild. This method describes whetherMessage.getGuild()
is usable.This can be
false
for messages sent via webhooks, or in the context of interactions.- Specified by:
hasGuild
in interfaceMessage
- Returns:
- True, if
Message.getGuild()
is provided
-
getGuildIdLong
public long getGuildIdLong()Description copied from interface:Message
The ID for the guild this message was sent in.
This is useful whenMessage.getGuild()
is not provided, for instance on webhook messages.- Specified by:
getGuildIdLong
in interfaceMessage
- Returns:
- The guild id, or 0 if this message was not sent in a guild
-
getGuild
Description copied from interface:Message
Returns theGuild
that this message was sent in.
This is just a shortcut toMessage.getGuildChannel()
.getGuild()
.
This is only valid if the Message was actually sent in a GuildMessageChannel.
You can check the type of channel this message was sent from usingMessage.isFromType(ChannelType)
orMessage.getChannelType()
. -
getAttachments
Description copied from interface:Message
An immutable list ofAttachments
that are attached to this message.
Most likely this will only ever be 1Attachment
at most.Requires
GatewayIntent.MESSAGE_CONTENT
- Specified by:
getAttachments
in interfaceMessage
- Returns:
- Immutable list of
Attachments
.
-
getEmbeds
Description copied from interface:Message
An immutable list ofMessageEmbeds
that are part of this Message.Requires
GatewayIntent.MESSAGE_CONTENT
-
getComponents
Description copied from interface:Message
Layouts of interactive components, usuallyActionRows
.
You can useMessageRequest.setComponents(MessageTopLevelComponent...)
to update these.Requires
GatewayIntent.MESSAGE_CONTENT
- Specified by:
getComponents
in interfaceMessage
- Returns:
- Immutable
List
ofMessageTopLevelComponent
- See Also:
-
isUsingComponentsV2
public boolean isUsingComponentsV2()Description copied from interface:Message
Whether this message can contain V2 components.
This checks forMessage.MessageFlag.IS_COMPONENTS_V2
.- Specified by:
isUsingComponentsV2
in interfaceMessage
- Returns:
true
if this message has the components V2 flag- See Also:
-
getPoll
Description copied from interface:Message
TheMessagePoll
attached to this message. -
endPoll
Description copied from interface:Message
End the poll attached to this message.- Specified by:
endPoll
in interfaceMessage
- Returns:
AuditableRestAction
- Type:Message
-
getMentions
Description copied from interface:Message
TheMentions
used in this message.This includes
Members
,GuildChannels
,Roles
, andCustomEmojis
. Can also be used to check if a message mentions@everyone
or@here
.Example
System.out.println("Message mentioned these users: " + message.getMentions().getUsers()); System.out.println("Message used these custom emojis: " + message.getMentions().getCustomEmojis());
- Specified by:
getMentions
in interfaceMessage
- Returns:
Mentions
for this message.
-
getReactions
Description copied from interface:Message
AllMessageReactions
that are on this Message.- Specified by:
getReactions
in interfaceMessage
- Returns:
- Immutable list of all MessageReactions on this message.
- See Also:
-
getStickers
Description copied from interface:Message
AllStickerItems
that are in this Message.
The returned StickerItems may only contain necessary information such as the sticker id, format type, name, and icon url.- Specified by:
getStickers
in interfaceMessage
- Returns:
- Immutable list of all StickerItems in this message.
-
getMessageSnapshots
Description copied from interface:Message
TheMessageSnaphots
attached to this message.This is used primarily for message forwarding. The content of the forwarded message is provided as a snapshot at the time of forwarding. When the message is edited or deleted, this snapshot remains unchanged.
- Specified by:
getMessageSnapshots
in interfaceMessage
- Returns:
- Immutable
List
ofMessageSnapshot
-
isWebhookMessage
public boolean isWebhookMessage()Description copied from interface:Message
Indicates if this Message was sent either by aWebhook
or an app, instead of aUser
.
Useful if you want to ignore non-users.- Specified by:
isWebhookMessage
in interfaceMessage
- Returns:
- True if this message was sent by a
Webhook
.
-
getApplicationIdLong
public long getApplicationIdLong()Description copied from interface:Message
If this message is from an application-ownedWebhook
or is a response to anInteraction
, this will return the application's id.- Specified by:
getApplicationIdLong
in interfaceMessage
- Returns:
- The application's id or 0 if this message was not sent by an application
-
hasChannel
public boolean hasChannel()Description copied from interface:Message
Whether this message instance has an availableMessage.getChannel()
.This can be
false
for messages sent via webhooks, or in the context of interactions.- Specified by:
hasChannel
in interfaceMessage
- Returns:
- True, if
Message.getChannel()
is available
-
getChannelIdLong
public long getChannelIdLong()Description copied from interface:Message
The ID for the channel this message was sent in.
This is useful whenMessage.getChannel()
is unavailable, for instance on webhook messages.- Specified by:
getChannelIdLong
in interfaceMessage
- Returns:
- The channel id
-
isTTS
public boolean isTTS()Description copied from interface:Message
Defines whether or not this Message triggers TTS (Text-To-Speech). -
getActivity
Description copied from interface:Message
AMessageActivity
that contains its type and party id.- Specified by:
getActivity
in interfaceMessage
- Returns:
- The activity, or
null
if no activity was added to the message.
-
editMessage
Description copied from interface:Message
Edits this message and updates the content.
Any other fields of the message will remain unchanged, you can usereplace(true)
to remove everything else (embeds/attachments/components).The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessage
in interfaceMessage
- Parameters:
newContent
- The new content of the message, or empty string to remove content (assumes other fields exist like embeds)- Returns:
MessageEditAction
- See Also:
-
editMessageEmbeds
@Nonnull public MessageEditAction editMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Description copied from interface:Message
Edits this message using the providedMessageEmbeds
.
You can useEmbedBuilder
to create aMessageEmbed
instance.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageEmbeds
in interfaceMessage
- Parameters:
embeds
- The newMessageEmbeds
of the message, empty list to remove embeds- Returns:
MessageEditAction
- See Also:
-
editMessageComponents
@Nonnull public MessageEditAction editMessageComponents(@Nonnull Collection<? extends MessageTopLevelComponent> components) Description copied from interface:Message
Edits this message using the providedMessageTopLevelComponents
.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageComponents
in interfaceMessage
- 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:
MessageEditAction
- See Also:
-
editMessageFormat
@Nonnull public MessageEditAction editMessageFormat(@Nonnull String format, @Nonnull Object... args) Description copied from interface:Message
Edits this message using the provided format arguments.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessageFormat
in interfaceMessage
- Parameters:
format
- Format String used to generate new Contentargs
- The arguments which should be used to format the given format String- Returns:
MessageEditAction
- See Also:
-
editMessageAttachments
@Nonnull public MessageEditAction editMessageAttachments(@Nonnull Collection<? extends AttachedFile> attachments) Description copied from interface:Message
Edits this message using the provided files.The following
ErrorResponses
are possible:REQUEST_ENTITY_TOO_LARGE
If any of the provided files is bigger thanGuild.getMaxFileSize()
MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted. This might also be triggered for ephemeral messages, if the interaction expired.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
Resource Handling Note: Once the request is handed off to the requester, for example when you call
RestAction.queue()
, the requester will automatically clean up all opened files by itself. You are only responsible to close them yourself if it is never handed off properly. For instance, if an exception occurs after usingFileUpload.fromData(File)
, before callingRestAction.queue()
. You can safely use a try-with-resources to handle this, sinceFileUpload.close()
becomes ineffective once the request is handed off.- Specified by:
editMessageAttachments
in interfaceMessage
- Parameters:
attachments
- The new attachments of the message (Can beFileUploads
orAttachmentUpdates
)- Returns:
MessageEditAction
that can be used to further update the message- See Also:
-
editMessage
Description copied from interface:Message
Edits this message using the providedMessageEditData
.
You can useMessageEditBuilder
to create aMessageEditData
instance.The following
ErrorResponses
are possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildMessageChannel
UNKNOWN_MESSAGE
The providedmessageId
is unknown in this MessageChannel, either due to the id being invalid, or the message it referred to has already been deleted.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.INVALID_FORM_BODY
Components V2 is used by the to-be-edited message, and this request has non-empty content or embeds.
- Specified by:
editMessage
in interfaceMessage
- Parameters:
newContent
- TheMessageEditData
used to update the message- Returns:
MessageEditAction
- See Also:
-
delete
Description copied from interface:Message
Deletes this Message from Discord.
If this Message was not sent by the currently logged in account, then this will fail unless the Message is from aGuildChannel
and the current account hasPermission.MESSAGE_MANAGE
in the channel.To delete many messages at once in a
MessageChannel
you should useMessageChannel.purgeMessages(List)
instead.The following
ErrorResponses
are possible:MISSING_ACCESS
The delete was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked, or the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The delete was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
when deleting another Member's message or lostPermission.MESSAGE_MANAGE
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages, if the interaction expired.
- Specified by:
delete
in interfaceMessage
- Returns:
AuditableRestAction
- See Also:
-
suppressEmbeds
Description copied from interface:Message
Enables/Disables suppression of Embeds on this Message.
Suppressing Embeds is equivalent to pressing theX
in the top-right corner of an Embed inside the Discord client.The following
ErrorResponses
are possible:MISSING_ACCESS
The clear-reactions request was attempted after the account lost access to theGuildChannel
due toPermission.VIEW_CHANNEL
being revoked, or the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The suppress-embeds request was attempted after the account lostPermission.MESSAGE_MANAGE
in theGuildChannel
when adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Specified by:
suppressEmbeds
in interfaceMessage
- Parameters:
suppressed
- Whether the embed should be suppressed- Returns:
AuditableRestAction
- Type:Void
- See Also:
-
crosspost
Description copied from interface:Message
Attempts to crosspost this message.The following
ErrorResponses
are possible:ALREADY_CROSSPOSTED
The target message has already been crossposted.MISSING_ACCESS
The request was attempted after the account lost access to theGuild
typically due to being kicked or removed, or afterPermission.VIEW_CHANNEL
was revoked in theGuildChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in the GuildMessageChannel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
- Specified by:
crosspost
in interfaceMessage
- Returns:
RestAction
- Type:Message
-
isSuppressedEmbeds
public boolean isSuppressedEmbeds()Description copied from interface:Message
Whether embeds are suppressed for this message. When Embeds are suppressed, they are not displayed on clients nor provided via API until un-suppressed.
This is a shortcut method for checking ifgetFlags()
containsMessageFlag#EMBEDS_SUPPRESSED
- Specified by:
isSuppressedEmbeds
in interfaceMessage
- Returns:
- Whether or not Embeds are suppressed for this Message.
- See Also:
-
getFlags
Description copied from interface:Message
Returns an EnumSet of allMessageFlags
present for this Message.- Specified by:
getFlags
in interfaceMessage
- Returns:
- Never-Null EnumSet of present
MessageFlags
- See Also:
-
getFlagsRaw
public long getFlagsRaw()Description copied from interface:Message
Returns the raw message flags of this message- Specified by:
getFlagsRaw
in interfaceMessage
- Returns:
- The raw message flags
- See Also:
-
isEphemeral
public boolean isEphemeral()Description copied from interface:Message
Whether this message is ephemeral.
The message being ephemeral means it is only visible to the bot and the interacting user
This is a shortcut method for checking ifMessage.getFlags()
containsMessage.MessageFlag.EPHEMERAL
- Specified by:
isEphemeral
in interfaceMessage
- Returns:
- Whether the message is ephemeral
-
isSuppressedNotifications
public boolean isSuppressedNotifications()Description copied from interface:Message
Whether this message is silent.
The message being silent means it will not trigger push and desktop notifications
This is a shortcut method for checking ifMessage.getFlags()
containsMessage.MessageFlag.NOTIFICATIONS_SUPPRESSED
- Specified by:
isSuppressedNotifications
in interfaceMessage
- Returns:
- Whether the message is silent
-
isVoiceMessage
public boolean isVoiceMessage()Description copied from interface:Message
Whether this message is a voice message.- Specified by:
isVoiceMessage
in interfaceMessage
- Returns:
- True, if this is a voice message
-
getStartedThread
Description copied from interface:Message
Returns a possiblynull
ThreadChannel
that was started from this message. This can benull
due to no ThreadChannel being started from it or the ThreadChannel later being deleted.- Specified by:
getStartedThread
in interfaceMessage
- Returns:
- The
ThreadChannel
that was started from this message.
-
createThreadChannel
Description copied from interface:Message
Creates a new, publicThreadChannel
spawning/starting at thisMessage
inside theIThreadContainer
this message was sent in.
The starting message will copy this message, and will be of typeMessageType.THREAD_STARTER_MESSAGE
.The resulting
ThreadChannel
may be one of:Possible
ErrorResponses
caused by the returnedRestAction
include the following:MISSING_PERMISSIONS
The channel could not be created due to a permission discrepancyMAX_CHANNELS
The maximum number of channels were exceededErrorResponse.THREAD_WITH_THIS_MESSAGE_ALREADY_EXISTS
This message has already been used to create a threadErrorResponse.MAX_ACTIVE_THREADS
The maximum number of active threads has been reached, and no more may be created.
- Specified by:
createThreadChannel
in interfaceMessage
- Parameters:
name
- The name of the new ThreadChannel (up to 100 characters)- Returns:
- A specific
ThreadChannelAction
that may be used to configure the new ThreadChannel before its creation.
-
equals
-
hashCode
public int hashCode() -
toString
-
formatTo
- Specified by:
formatTo
in interfaceFormattable
-