Interface Message
- All Superinterfaces:
Formattable
,ISnowflake
This represents messages received from
MessageChannels
.
This type is not updated. JDA does not keep track of changes to messages, it is advised to do this via events such
as MessageUpdateEvent
and similar.
Message Differences
There are 3 implementations of this interface in JDA.- Received Message
Messages received through events or history query. These messages hold information of existing messages and can be modified or deleted. - System Message
Specification of Received Messages that are generated by Discord on certain events. Commonly this is used in groups or to indicate a pin within a MessageChannel. The different types can be found in theMessageType
enum. - Data Message
This type is produced byMessageBuilder
and only holds sendable information such as content or nonce. These messages do not allow any modifications via RestActions or information that is generated when sent such as the id to be used.
When a feature is not available it will throw an UnsupportedOperationException
as per interface specifications.
Specific operations may have specified information available in the throws
javadoc.
Formattable
This interface extendsFormattable
and can be used with a Formatter
such as used by String.format(String, Object...)
or PrintStream.printf(String, Object...)
.
This will use getContentDisplay()
rather than Object.toString()
!
Supported Features:
- Alternative
- UsinggetContentRaw()
(Example:%#s
- usesgetContentDisplay()
) - Width/Left-Justification
- Ensures the size of a format (Example:%20s
- uses at minimum 20 chars;%-10s
- uses left-justified padding) - Precision
- Cuts the content to the specified size (replacing last 3 chars with...
; Example:%.20s
)
More information on formatting syntax can be found in the format syntax documentation
!
- See Also:
-
MessageBuilder
MessageChannel.sendMessage(Message)
MessageChannel.getIterableHistory()
MessageChannel.getHistory()
MessageChannel.getHistoryAfter(String, int)
MessageChannel.getHistoryBefore(String, int)
MessageChannel.getHistoryAround(String, int)
MessageChannel.getHistoryFromBeginning(int)
MessageChannel.retrieveMessageById(String)
MessageChannel.deleteMessageById(String)
MessageChannel.editMessageById(String, CharSequence)
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Represents aMessage
file attachment.static class
Represents anInteraction
provided with aMessage
.static enum
Mention constants, useful for use withPatterns
static enum
Enum representing the flags on a Message. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
Pattern used to find instant invites in strings.static final Pattern
Pattern used to findJump URLs
in strings.static final int
The maximum amount of characters sendable in one message.static final int
The maximum amount of files sendable within a single message (10)static final int
The maximum sendable file size (8 MiB)static final int
The maximum sendable file size for nitro (50 MiB)static final int
The maximum amount of reactions that can be added to one message (20) -
Method Summary
Modifier and TypeMethodDescriptionaddReaction
(String unicode) Adds a reaction to this Message using a unicode emoji.addReaction
(Emote emote) Adds a reaction to this Message using anEmote
.Removes all reactions from this Message.clearReactions
(String unicode) Removes all reactions for the specified emoji.clearReactions
(Emote emote) Removes all reactions for the specified emote.createThreadChannel
(String name) Attempts to crosspost this message.delete()
Deletes this Message from Discord.editMessage
(CharSequence newContent) Edits this Message's content to the provided String.editMessage
(Message newContent) Edits this Message's content to the providedMessage
.editMessageComponents
(Collection<? extends LayoutComponent> components) Edits this Message's content to the providedLayoutComponents
.default MessageAction
editMessageComponents
(LayoutComponent... components) Edits this Message's content to the providedLayoutComponents
.editMessageEmbeds
(Collection<? extends MessageEmbed> embeds) Edits this Message's content to the providedMessageEmbeds
.default MessageAction
editMessageEmbeds
(MessageEmbed... embeds) Edits this Message's content to the providedMessageEmbeds
.editMessageFormat
(String format, Object... args) Edits this Message's content to the provided format.Rows of interactive components such asButtons
.AMessageActivity
that contains its type and party id.An immutable list ofAttachments
that are attached to this message.The author of this Messagedefault Button
getButtonById
(String id) Gets theButton
with the specified ID.AllButtons
attached to this message.getButtonsByLabel
(String label, boolean ignoreCase) AllButtons
with the specified label attached to this message.TheCategory
this message was sent in.Returns theMessageChannel
that this message was sent in.Gets theChannelType
that this message was received from.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 usinggetContentDisplay()
and then strips it of markdown characters like *, **, __, ~~, || that provide text formatting.An immutable list ofMessageEmbeds
that are part of this Message.AllEmotes
used in this Message.org.apache.commons.collections4.Bag<Emote>
ABag
of emotes used in 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.This is sent on the message object when the message is a response to anInteraction
without an existing message.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
.A immutable list of all mentionedTextChannels
.org.apache.commons.collections4.Bag<TextChannel>
ABag
of mentioned channels.Creates an immutable list ofMembers
representing the users ofgetMentionedUsers()
in theGuild
this Message was sent in.getMentionedMembers
(Guild guild) Creates an immutable list ofMembers
representing the users ofgetMentionedUsers()
in the specifiedGuild
.A immutable list of all mentionedRoles
.org.apache.commons.collections4.Bag<Role>
ABag
of mentioned roles.An immutable list of all mentionedUsers
.org.apache.commons.collections4.Bag<User>
ABag
of mentioned users.getMentions
(Message.MentionType... types) Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.Returns theMessageReference
for this Message.Returns theNewsChannel
that this message was sent in.getNonce()
Validation nonce for this Message
This can be used to validate that a Message was properly sent to the Discord Service.Returns thePrivateChannel
that this message was sent in.getReactionById
(long id) This obtains theReactionEmote
for the given reaction id on this message.This obtains theReactionEmote
for the given reaction id on this message.getReactionByUnicode
(String unicode) This obtains theReactionEmote
for the given unicode reaction on this message.AllMessageReactions
that are on this Message.default Message
Referenced message.AllMessageStickers
that are in this Message.Returns theTextChannel
that this message was sent in.Provides theOffsetDateTime
defining when this Message was last edited.getType()
This specifies theMessageType
of this Message.boolean
isEdited()
Returns whether or not this Message has been edited before.boolean
Whether this message is ephemeral.default 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
isMentioned
(IMentionable mentionable, Message.MentionType... types) Checks if givenIMentionable
was mentioned in this message in any way (@User, @everyone, @here, @Role).boolean
isPinned()
Whether or not this Message has been pinned in its parent channel.boolean
Whether embeds are suppressed for this message.boolean
isTTS()
Defines whether or not this Message triggers TTS (Text-To-Speech).boolean
boolean
Indicates if this Message mentions everyone using @everyone or @here.pin()
Used to add the Message to theMessageChannel's
pinned message list.removeReaction
(String unicode) Removes a reaction from this Message using a unicode emoji.removeReaction
(String unicode, User user) Removes a reaction from this Message using a unicode emoji.removeReaction
(Emote emote) Removes a reaction from this Message using anEmote
.removeReaction
(Emote emote, User user) default MessageAction
reply
(byte[] data, String name, AttachmentOption... options) Replies and references this message.default MessageAction
reply
(File data, String name, AttachmentOption... options) Replies and references this message.default MessageAction
reply
(File file, AttachmentOption... options) Replies and references this message.default MessageAction
reply
(InputStream data, String name, AttachmentOption... options) Replies and references this message.default MessageAction
reply
(CharSequence content) Replies and references this message.default MessageAction
Replies and references this message.default MessageAction
replyEmbeds
(Collection<? extends MessageEmbed> embeds) Replies and references this message.default MessageAction
replyEmbeds
(MessageEmbed embed, MessageEmbed... other) Replies and references this message.default MessageAction
replyFormat
(String format, Object... args) Replies and references this message.retrieveReactionUsers
(String unicode) This obtains theusers
who reacted using the given unicode emoji.retrieveReactionUsers
(Emote emote) suppressEmbeds
(boolean suppressed) Enables/Disables suppression of Embeds on this Message.unpin()
Used to remove the Message from theMessageChannel's
pinned message list.Methods inherited from interface java.util.Formattable
formatTo
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
Field Details
-
MAX_FILE_SIZE
static final int MAX_FILE_SIZEThe maximum sendable file size (8 MiB) -
MAX_FILE_SIZE_NITRO
static final int MAX_FILE_SIZE_NITROThe maximum sendable file size for nitro (50 MiB) -
MAX_FILE_AMOUNT
static final int MAX_FILE_AMOUNTThe maximum amount of files sendable within a single message (10) -
MAX_CONTENT_LENGTH
static final int MAX_CONTENT_LENGTHThe maximum amount of characters sendable in one message. (2000)
This only applies to the raw content and not embeds! -
MAX_REACTIONS
static final int MAX_REACTIONSThe maximum amount of reactions that can be added to one message (20) -
INVITE_PATTERN
Pattern used to find instant invites in strings.The only named group is at index 1 with the name
"code"
.- See Also:
-
JUMP_URL_PATTERN
Pattern used to findJump URLs
in strings.Groups
Index Name Description 0 N/A The entire link 1 guild The ID of the target guild 2 channel The ID of the target channel 3 message The ID of the target message Matcher.group(String)
and the index withMatcher.group(int)
.- See Also:
-
-
Method Details
-
getMessageReference
Returns theMessageReference
for this Message. This will be null if this Message has no reference.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()
.- Returns:
- The message reference, or null.
-
getReferencedMessage
Referenced message.This will have different meaning depending on the
type
of message. Usually, this is aINLINE_REPLY
reference. This can be null even if the type isINLINE_REPLY
, when the message it references doesn't exist or discord wasn't able to resolve it in time.This differs from a
MessageReference
, which contains the raw IDs attached to the reference, and allows you to retrieve the referenced message- Returns:
- The referenced message, or null
- See Also:
-
getMentionedUsers
An immutable list of all mentionedUsers
.
If no user was mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the user and not mentions through roles or the everyone tag.- Returns:
- immutable list of mentioned users
- Throws:
UnsupportedOperationException
- If this is a system message
-
getMentionedUsersBag
ABag
of mentioned users.
This can be used to retrieve the amount of times a user was mentioned in this message. This only counts direct mentions of the user and not mentions through roles or the everyone tag.Example
public void sendCount(Message msg) { List<User> mentions = msg.getMentionedUsers(); // distinct list, in order of appearance Bag<User> count = msg.getMentionedUsersBag(); StringBuilder content = new StringBuilder(); for (User user : mentions) { content.append(user.getAsTag()) .append(": ") .append(count.getCount(user)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Returns:
Bag
of mentioned users- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getMentionedChannels
A immutable list of all mentionedTextChannels
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance.This may include TextChannels from other
Guilds
- Returns:
- immutable list of mentioned TextChannels
- Throws:
UnsupportedOperationException
- If this is a system message
-
getMentionedChannelsBag
ABag
of mentioned channels.
This can be used to retrieve the amount of times a channel was mentioned in this message.Example
public void sendCount(Message msg) { List<TextChannel> mentions = msg.getMentionedTextChannels(); // distinct list, in order of appearance Bag<TextChannel> count = msg.getMentionedTextChannelsBag(); StringBuilder content = new StringBuilder(); for (TextChannel channel : mentions) { content.append("#") .append(channel.getName()) .append(": ") .append(count.getCount(channel)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Returns:
Bag
of mentioned channels- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getMentionedRoles
A immutable list of all mentionedRoles
.
If none were mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the role and not mentions through the everyone tag.This may include Roles from other
Guilds
- Returns:
- immutable list of mentioned Roles
- Throws:
UnsupportedOperationException
- If this is a system message
-
getMentionedRolesBag
ABag
of mentioned roles.
This can be used to retrieve the amount of times a role was mentioned in this message. This only counts direct mentions of the role and not mentions through the everyone tag. If a role is notmentionable
it will not be included.Example
public void sendCount(Message msg) { List<Role> mentions = msg.getMentionedRoles(); // distinct list, in order of appearance Bag<Role> count = msg.getMentionedRolesBag(); StringBuilder content = new StringBuilder(); for (Role role : mentions) { content.append(role.getName()) .append(": ") .append(count.getCount(role)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Returns:
Bag
of mentioned roles- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getMentionedMembers
Creates an immutable list ofMembers
representing the users ofgetMentionedUsers()
in the specifiedGuild
.
This is only a convenience method and will skip all users that are not in the specified Guild.- Parameters:
guild
- Non-nullGuild
that will be used to retrieve Members.- Returns:
- Immutable list of mentioned Members
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalArgumentException
- If the specified Guild isnull
- Since:
- 3.4.0
-
getMentionedMembers
Creates an immutable list ofMembers
representing the users ofgetMentionedUsers()
in theGuild
this Message was sent in.
This is only a convenience method and will skip all users that are not in the specified Guild.
It will provide thegetGuild()
output Guild togetMentionedMembers(Guild)
.- Returns:
- Immutable list of mentioned Members
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this message was not sent in aTextChannel
- Since:
- 3.4.0
-
getMentions
Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.
This does not includegetMentionedMembers()
to avoid duplicates.If no MentionType values are given this will fallback to all types.
- Parameters:
types
- Amount ofMentionTypes
to include in the list of mentions- Returns:
- Immutable list of filtered
IMentionable
instances - Throws:
UnsupportedOperationException
- If this is a system messageIllegalArgumentException
- If provided withnull
- Since:
- 3.4.0
-
isMentioned
Checks if givenIMentionable
was mentioned in this message in any way (@User, @everyone, @here, @Role).
If no filteringMentionTypes
are specified this will fallback to all mention types.MentionType.HERE
andMentionType.EVERYONE
will only be checked, if the givenIMentionable
is of typeUser
orMember
.
Online status of Users/Members is NOT considered when checkingMentionType.HERE
.- Parameters:
mentionable
- The mentionable entity to check on.types
- The types to include when checking whether this type was mentioned. This will be used withgetMentions(MentionType...)
- Returns:
- True, if the given mentionable was mentioned in this message
- Throws:
UnsupportedOperationException
- If this is a system message
-
mentionsEveryone
boolean mentionsEveryone()Indicates if this Message mentions everyone using @everyone or @here.- Returns:
- True, if message is mentioning everyone
- Throws:
UnsupportedOperationException
- If this is a system message
-
isEdited
boolean isEdited()Returns whether or not this Message has been edited before.- Returns:
- True if this message has been edited.
- Throws:
UnsupportedOperationException
- If this is a system message
-
getTimeEdited
Provides theOffsetDateTime
defining when this Message was last edited. If this Message has not been edited (isEdited()
isfalse
), then this method will returnnull
.- Returns:
- Time of the most recent edit, or
null
if the Message has never been edited. - Throws:
UnsupportedOperationException
- If this is a system message
-
getAuthor
The author of this Message- Returns:
- Message author
- Throws:
UnsupportedOperationException
- If this is a system message
-
getMember
Returns the author of this Message as amember
.
This is only valid if the Message was actually sent in a TextChannel. This will returnnull
if the message was not sent in a TextChannel, or if the message was sent by a Webhook.
You can check the type of channel this message was sent from usingisFromType(ChannelType)
orgetChannelType()
.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.- Returns:
- Message author, or
null
if the message was not sent in a TextChannel, or if the message was sent by a Webhook. - Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getJumpUrl
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.- Returns:
- A String representing the jump-to URL for the message
- Throws:
UnsupportedOperationException
- If this is a system message
-
getContentDisplay
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,TextChannels
to their #ChannelName format,Roles
to their @RoleName formatEmotes
(not emojis!) to their:name:
format.If you want the actual Content (mentions as <@id>), use
getContentRaw()
instead- Returns:
- The textual content of the message with mentions resolved to be visually like the Discord client.
- Throws:
UnsupportedOperationException
- If this is a system message
-
getContentRaw
The raw textual content of this message. Does not resolveIMentionable
entities likegetContentDisplay()
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.- Returns:
- The raw textual content of the message, containing unresolved Discord message formatting.
-
getContentStripped
Gets the textual content of this message usinggetContentDisplay()
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.- Returns:
- The textual content from
getContentDisplay()
with all text formatting characters removed or escaped. - Throws:
UnsupportedOperationException
- If this is a system message
-
getInvites
Creates an immutable List ofInvite
codes that are included in this Message.
This will use thePattern
provided underINVITE_PATTERN
to construct aMatcher
that will parse thegetContentRaw()
output and include all codes it finds in a list.You can use the codes to retrieve/validate invites via
Invite.resolve(JDA, String)
- Returns:
- Immutable list of invite codes
- Throws:
UnsupportedOperationException
- If this is a system message
-
getNonce
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 useMessageBuilder.setNonce(String)
!- Returns:
- The validation nonce
- Since:
- 3.4.0
- See Also:
-
isFromType
Used to determine if this Message was received from aMessageChannel
of theChannelType
specified.
This will always be false forChannelType.VOICE
as Messages can't be sent toVoiceChannels
.Useful for restricting functionality to a certain type of channels.
- 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
. - Throws:
UnsupportedOperationException
- If this is a system message
-
isFromGuild
default boolean isFromGuild()Whether this message was sent in aGuild
.
If this isfalse
thengetGuild()
will throw anIllegalStateException
.- Returns:
- True, if
getChannelType()
.isGuild()
is true.
-
getChannelType
Gets theChannelType
that this message was received from.
This will never beChannelType.VOICE
as Messages can't be sent toVoiceChannels
.- Returns:
- The ChannelType which this message was received from.
- Throws:
UnsupportedOperationException
- If this is a system message
-
isWebhookMessage
boolean isWebhookMessage()Indicates if this Message was sent by aWebhook
instead of aUser
.
Useful if you want to ignore non-users.- Returns:
- True if this message was sent by a
Webhook
. - Throws:
UnsupportedOperationException
- If this is a system message
-
getChannel
Returns theMessageChannel
that this message was sent in.- Returns:
- The MessageChannel of this Message
- Throws:
UnsupportedOperationException
- If this is a system message
-
getGuildChannel
Returns theGuildMessageChannel
that this message was sent in if it was sent in a Guild.- Returns:
- The MessageChannel of this Message
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this was not sent in aGuild
.
-
getPrivateChannel
Returns thePrivateChannel
that this message was sent in.
This is only valid if the Message was actually sent in a PrivateChannel.
You can check the type of channel this message was sent from usingisFromType(ChannelType)
orgetChannelType()
.Use
getChannel()
for an ambiguousMessageChannel
if you do not need functionality specific toPrivateChannel
.- Returns:
- The PrivateChannel this message was sent in
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this was not sent in aPrivateChannel
.- See Also:
-
getTextChannel
Returns theTextChannel
that this message was sent in.
This is only valid if the Message was actually sent in a TextChannel.
You can check the type of channel this message was sent from usingisFromType(ChannelType)
orgetChannelType()
.Use
getChannel()
for an ambiguousMessageChannel
if you do not need functionality specific toTextChannel
.- Returns:
- The TextChannel this message was sent in
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this was not sent in aTextChannel
.- See Also:
-
getNewsChannel
Returns theNewsChannel
that this message was sent in.
This is only valid if the Message was actually sent in a NewsChannel.
You can check the type of channel this message was sent from usingisFromType(ChannelType)
orgetChannelType()
.Use
getChannel()
for an ambiguousMessageChannel
if you do not need functionality specific toNewsChannel
.- Returns:
- The NewsChannel this message was sent in
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this was not sent in aNewsChannel
.- See Also:
-
getCategory
TheCategory
this message was sent in. This will always benull
for DMs.
Equivalent togetTextChannel().getParentCategory()
if this was sent in aTextChannel
.- Returns:
Category
for this message- Throws:
UnsupportedOperationException
- If this is a system message
-
getGuild
Returns theGuild
that this message was sent in.
This is just a shortcut togetTextChannel()
.getGuild()
.
This is only valid if the Message was actually sent in a TextChannel.
You can check the type of channel this message was sent from usingisFromType(ChannelType)
orgetChannelType()
.- Returns:
- The Guild this message was sent in
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If this was not sent in aTextChannel
.- See Also:
-
getAttachments
An immutable list ofAttachments
that are attached to this message.
Most likely this will only ever be 1Attachment
at most.- Returns:
- Immutable list of
Attachments
. - Throws:
UnsupportedOperationException
- If this is a system message
-
getEmbeds
An immutable list ofMessageEmbeds
that are part of this Message.- Returns:
- Immutable list of all given MessageEmbeds.
- Throws:
UnsupportedOperationException
- If this is a system message
-
getActionRows
Rows of interactive components such asButtons
.
You can useMessageAction.setActionRows(ActionRow...)
to update these. -
getButtons
AllButtons
attached to this message. -
getButtonById
Gets theButton
with the specified ID.- Parameters:
id
- The id of the button- Returns:
- The
Button
or null of no button with that ID is present on this message - Throws:
IllegalArgumentException
- If the id is null
-
getButtonsByLabel
AllButtons
with the specified label attached to this message.- Parameters:
label
- The button labelignoreCase
- Whether to useString.equalsIgnoreCase(String)
instead ofString.equals(Object)
- Returns:
- Immutable
List
ofButtons
with the specified label - Throws:
IllegalArgumentException
- If the provided label is null
-
getEmotes
AllEmotes
used in this Message.
This only includes Custom Emotes, not unicode Emojis. JDA classifies Emotes as the Custom Emojis uploaded to a Guild and retrievable withGuild.getEmotes()
. These are not the same as the unicode emojis that Discord also supports. Elements are sorted in order of appearance.Unicode emojis are not included as
Emote
!- Returns:
- An immutable list of the Emotes used in this message (example match <:jda:230988580904763393>)
- Throws:
UnsupportedOperationException
- If this is a system message
-
getEmotesBag
ABag
of emotes used in this message.
This can be used to retrieve the amount of times an emote was used in this message.Example
public void sendCount(Message msg) { List<Emote> emotes = msg.getEmotes(); // distinct list, in order of appearance Bag<Emote> count = msg.getEmotesBag(); StringBuilder content = new StringBuilder(); for (Emote emote : emotes) { content.append(emote.getName()) .append(": ") .append(count.getCount(role)) .append("\n"); } msg.getChannel().sendMessage(content.toString()).queue(); }
- Returns:
Bag
of used emotes- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getReactions
AllMessageReactions
that are on this Message.- Returns:
- Immutable list of all MessageReactions on this message.
- Throws:
UnsupportedOperationException
- If this is a system message
-
getStickers
AllMessageStickers
that are in this Message.
The returned MessageStickers may only contain necessary information such as the sticker id, format type, name, and icon url.- Returns:
- Immutable list of all MessageStickers in this message.
- Throws:
UnsupportedOperationException
- If this is a system message
-
isTTS
boolean isTTS()Defines whether or not this Message triggers TTS (Text-To-Speech).- Returns:
- If this message is TTS.
-
getActivity
AMessageActivity
that contains its type and party id.- Returns:
- The activity, or
null
if no activity was added to the message.
-
editMessage
Edits this Message's content to the provided String.
Messages can only be edited by the account that sent them!.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:MISSING_ACCESS
The edit was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The edit was attempted after the account lostPermission.MESSAGE_SEND
in theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
newContent
- the new content of the Message- Returns:
MessageAction
TheMessage
with the updated content- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
- If the message attempting to be edited was not created by the currently logged in account, or ifnewContent
's length is 0 or greater than 2000.
-
editMessageEmbeds
@Nonnull @CheckReturnValue MessageAction editMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Edits this Message's content to the providedMessageEmbeds
.
Messages can only be edited by the account that sent them!.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:MISSING_ACCESS
The edit was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The edit was attempted after the account lostPermission.MESSAGE_SEND
in theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
embeds
- the new embeds of the Message (up to 10)- Returns:
MessageAction
TheMessage
with the updated content- Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
IllegalStateException
- If the message attempting to be edited was not created by the currently logged in accountIllegalArgumentException
- if any of the passed-in embeds isnull
or notsendable
.
-
editMessageEmbeds
Edits this Message's content to the providedMessageEmbeds
.
Messages can only be edited by the account that sent them!.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:MISSING_ACCESS
The edit was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The edit was attempted after the account lostPermission.MESSAGE_SEND
in theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
embeds
- the new embeds of the Message (up to 10)- Returns:
MessageAction
TheMessage
with the updated content- Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
IllegalStateException
- If the message attempting to be edited was not created by the currently logged in accountIllegalArgumentException
- if any of the passed-in embeds isnull
or notsendable
.
-
editMessageComponents
@Nonnull @CheckReturnValue MessageAction editMessageComponents(@Nonnull Collection<? extends LayoutComponent> components) Edits this Message's content to the providedLayoutComponents
.
Messages can only be edited by the account that sent them!.
This will replace all the currentComponents
, such asButtons
orSelectMenus
on this message. The provided parameters areLayoutComponent
such asActionRow
which contain a list of components to arrange in the respective layout.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!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 theTextChannel
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.
Example
List<ActionRow> rows = Arrays.asList( ActionRow.of(Button.success("prompt:accept", "Accept"), Button.danger("prompt:reject", "Reject")), // 1st row below message ActionRow.of(Button.link(url, "Help")) // 2nd row below message ); message.editMessageComponents(rows).queue();
- Parameters:
components
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageAction
TheMessage
with the updated components- Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
or any of the component layouts is a custom implementation that is not supported by this interfaceIllegalArgumentException
- If null is provided, or more than 5 layouts are addedIllegalStateException
- If the message attempting to be edited was not created by the currently logged in account
-
editMessageComponents
@Nonnull @CheckReturnValue default MessageAction editMessageComponents(@Nonnull LayoutComponent... components) Edits this Message's content to the providedLayoutComponents
.
Messages can only be edited by the account that sent them!.
This will replace all the currentComponents
, such asButtons
orSelectMenus
on this message. The provided parameters areLayoutComponent
such asActionRow
which contain a list of components to arrange in the respective layout.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:INVALID_AUTHOR_EDIT
Attempted to edit a message that was not sent by the currently logged in account. Discord does not allow editing of other users' Messages!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 theTextChannel
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.
Example
message.editMessageComponents( ActionRow.of(Button.success("prompt:accept", "Accept"), Button.danger("prompt:reject", "Reject")), // 1st row below message ActionRow.of(Button.link(url, "Help")) // 2nd row below message ).queue();
- Parameters:
components
- Up to 5 newLayoutComponents
for the edited message, such asActionRow
- Returns:
MessageAction
TheMessage
with the updated components- Throws:
UnsupportedOperationException
- If this is not a Received Message fromMessageType.DEFAULT
or any of the component layouts is a custom implementation that is not supported by this interfaceIllegalArgumentException
- If null is provided, or more than 5 layouts are addedIllegalStateException
- If the message attempting to be edited was not created by the currently logged in account
-
editMessageFormat
@Nonnull @CheckReturnValue MessageAction editMessageFormat(@Nonnull String format, @Nonnull Object... args) Edits this Message's content to the provided format.
Shortcut forMessageBuilder.appendFormat(String, Object...)
.
Messages can only be edited by the account that sent them!.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:MISSING_ACCESS
The edit was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The edit was attempted after the account lostPermission.MESSAGE_SEND
in theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
format
- Format String used to generate the Message's content viaMessageBuilder.appendFormat(String, Object...)
specificationargs
- The arguments to use in order to be converted in the format string- Returns:
MessageAction
TheMessage
with the updated content- Throws:
UnsupportedOperationException
- If this is a system messageIllegalArgumentException
- If the provided format String isnull
or blank, or if the created message exceeds the 2000 character limitIllegalFormatException
- If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.IllegalStateException
- If the message attempting to be edited was not created by the currently logged in account
-
editMessage
Edits this Message's content to the providedMessage
.
Messages can only be edited by the account that sent them!.This message instance will not be updated by this operation, please use the response message instead.
The following
ErrorResponses
are possible:MISSING_ACCESS
The edit was attempted after the account lost access to theGuild
typically due to being kicked or removed.MISSING_PERMISSIONS
The edit was attempted after the account lostPermission.MESSAGE_SEND
in theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
newContent
- the new content of the Message- Returns:
MessageAction
TheMessage
with the updated content- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
-- If the message attempting to be edited was not created by the currently logged in account
- If the message contains a MessageEmbed that is not
sendable
-
reply
Replies and references this message.
This is identical tomessage.getChannel().sendMessage(content).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendMessage(CharSequence)
andMessageAction.reference(Message)
.- Parameters:
content
- The content of the reply message- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
replyEmbeds
@Nonnull @CheckReturnValue default MessageAction replyEmbeds(@Nonnull MessageEmbed embed, @Nonnull MessageEmbed... other) Replies and references this message.
This is identical tomessage.getChannel().sendMessageEmbeds(embeds).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendMessageEmbeds(MessageEmbed, MessageEmbed...)
andMessageAction.reference(Message)
.- Parameters:
embed
- The embed to reply withother
- Additional embeds to reply with- Returns:
MessageAction
Providing theMessage
created from this upload.- Throws:
IllegalArgumentException
- If null is provided, any of the embeds are notsendable
, more than 10 embeds are provided, or the sum ofMessageEmbed.getLength()
is greater thanMessageEmbed.EMBED_MAX_LENGTH_BOT
-
replyEmbeds
@Nonnull @CheckReturnValue default MessageAction replyEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Replies and references this message.
This is identical tomessage.getChannel().sendMessageEmbeds(embeds).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendMessageEmbeds(MessageEmbed, MessageEmbed...)
andMessageAction.reference(Message)
.- Parameters:
embeds
- The embeds to reply with- Returns:
MessageAction
Providing theMessage
created from this upload.- Throws:
IllegalArgumentException
- If null is provided, any of the embeds are notsendable
, more than 10 embeds are provided, or the sum ofMessageEmbed.getLength()
is greater thanMessageEmbed.EMBED_MAX_LENGTH_BOT
-
reply
Replies and references this message.
This is identical tomessage.getChannel().sendMessage(content).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendMessage(Message)
andMessageAction.reference(Message)
.- Parameters:
content
- The content of the reply message- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
replyFormat
@Nonnull @CheckReturnValue default MessageAction replyFormat(@Nonnull String format, @Nonnull Object... args) Replies and references this message.
This is identical tomessage.getChannel().sendMessageFormat(content, args).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendMessageFormat(String, Object...)
andMessageAction.reference(Message)
.- Parameters:
format
- The string that should be formatted, if this is null or empty the content of the Message would be empty and cause a builder exception.args
- The arguments for your format- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
reply
@Nonnull @CheckReturnValue default MessageAction reply(@Nonnull File file, @Nonnull AttachmentOption... options) Replies and references this message.
This is identical tomessage.getChannel().sendFile(file, options).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendFile(File, net.dv8tion.jda.api.utils.AttachmentOption...)
andMessageAction.reference(Message)
.- Parameters:
file
- The file to upload to the channel in the replyoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
reply
@Nonnull @CheckReturnValue default MessageAction reply(@Nonnull File data, @Nonnull String name, @Nonnull AttachmentOption... options) Replies and references this message.
This is identical tomessage.getChannel().sendFile(data, name, options).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendFile(File, String, net.dv8tion.jda.api.utils.AttachmentOption...)
andMessageAction.reference(Message)
.- Parameters:
data
- The data to upload to the channel in the replyname
- The name that should be sent to discordoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
reply
@Nonnull @CheckReturnValue default MessageAction reply(@Nonnull InputStream data, @Nonnull String name, @Nonnull AttachmentOption... options) Replies and references this message.
This is identical tomessage.getChannel().sendFile(data, name, options).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendFile(InputStream, String, net.dv8tion.jda.api.utils.AttachmentOption...)
andMessageAction.reference(Message)
.- Parameters:
data
- The data to upload to the channel in the replyname
- The name that should be sent to discordoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
reply
@Nonnull @CheckReturnValue default MessageAction reply(@Nonnull byte[] data, @Nonnull String name, @Nonnull AttachmentOption... options) Replies and references this message.
This is identical tomessage.getChannel().sendFile(data, name, options).reference(message)
. You can usementionRepliedUser(false)
to not mention the author of the message.
By default there won't be any error thrown if the referenced message does not exist. This behavior can be changed withMessageAction.failOnInvalidReply(boolean)
.For further info, see
MessageChannel.sendFile(byte[], String, net.dv8tion.jda.api.utils.AttachmentOption...)
andMessageAction.reference(Message)
.- Parameters:
data
- The data to upload to the channel in the replyname
- The name that should be sent to discordoptions
- Possible options to apply to this attachment, such as marking it as spoiler image- Returns:
MessageAction
Providing theMessage
created from this upload.- Since:
- 4.2.1
-
delete
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 aTextChannel
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 theTextChannel
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 theTextChannel
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.
- Returns:
AuditableRestAction
- Throws:
UnsupportedOperationException
- If this is a Data Message (output ofMessageBuilder
)InsufficientPermissionException
- If this Message was not sent by the currently logged in account, the Message was sent in aTextChannel
, and the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channel.IllegalStateException
-- If this Message was not sent by the currently logged in account and it was not sent in a
TextChannel
. - If this Message is ephemeral
- If this Message was not sent by the currently logged in account and it was not sent in a
- See Also:
-
getJDA
Returns theJDA
instance related to this Message.- Returns:
- the corresponding JDA instance
- Throws:
UnsupportedOperationException
- If this is a system message
-
isPinned
boolean isPinned()Whether or not this Message has been pinned in its parent channel.- Returns:
- True - if this message has been pinned.
- Throws:
UnsupportedOperationException
- If this is a system message
-
pin
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
isPinned()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The pin request was attempted after the account lost access to theTextChannel
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 theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If this Message is from aTextChannel
and:- Missing
Permission.VIEW_CHANNEL
.
The account needs access the the channel to pin a message in it. - Missing
Permission.MESSAGE_MANAGE
.
Required to actually pin the Message.
- Missing
IllegalStateException
- If this Message is ephemeral
-
unpin
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
isPinned()
.The following
ErrorResponses
are possible:MISSING_ACCESS
The unpin request was attempted after the account lost access to theTextChannel
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 theTextChannel
.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If this Message is from aTextChannel
and:- Missing
Permission.VIEW_CHANNEL
.
The account needs access the the channel to pin a message in it. - Missing
Permission.MESSAGE_MANAGE
.
Required to actually pin the Message.
- Missing
IllegalStateException
- If this Message is ephemeral
-
addReaction
Adds a reaction to this Message using anEmote
.This message instance will not be updated by this operation.
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/emote.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.Unicode emojis are not included as
Emote
!The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
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 theTextChannel
when adding the reaction.UNKNOWN_EMOJI
The provided emote 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.
- Parameters:
emote
- TheEmote
to add as a reaction to this Message.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not haveIllegalArgumentException
-- If the provided
Emote
is null. - If the provided
Emote
cannot be used in the current channel. SeeEmote.canInteract(User, MessageChannel)
orEmote.canInteract(Member)
for more information.
- If the provided
IllegalStateException
- If this message is ephemeral
-
addReaction
Adds a reaction to this Message using a unicode emoji.
A reference of unicode emojis can be found here: Emoji Table.This message instance will not be updated by this operation.
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/emote.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.Examples
// custom
message.addReaction("minn:245267426227388416").queue();
// unicode escape
message.addReaction("\uD83D\uDE02").queue();
// codepoint notation
message.addReaction("U+1F602").queue();The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
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
in theTextChannel
when adding the reaction.UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
unicode
- The unicode emoji to add as a reaction to this Message.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not haveIllegalArgumentException
- If the provided unicode emoji is null or empty.IllegalStateException
- If this Message is ephemeral
-
clearReactions
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
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 theTextChannel
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 theTextChannel
when adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channel.IllegalStateException
-- If this message was not sent in a
Guild
. - If this message is ephemeral
- If this message was not sent in a
-
clearReactions
Removes all reactions for the specified emoji.Please note that you can't clear reactions if this message was sent in a
PrivateChannel
!Example
// custom message.clearReactions("minn:245267426227388416").queue(); // unicode escape message.clearReactions("\uD83D\uDE02").queue(); // codepoint notation message.clearReactions("U+1F602").queue();
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 unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
unicode
- The unicode emoji to remove reactions for- Returns:
RestAction
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channelIllegalArgumentException
- If provided with nullIllegalStateException
-- If this message was not sent in a
Guild
. - If this message is ephemeral
- If this message was not sent in a
- Since:
- 4.2.0
-
clearReactions
Removes all reactions for the specified emote.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 emote 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.
- Parameters:
emote
- TheEmote
to remove reactions for- Returns:
RestAction
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channelIllegalArgumentException
- If provided with nullIllegalStateException
-- If this message was not sent in a
Guild
. - If this message is ephemeral
- If this message was not sent in a
- Since:
- 4.2.0
-
removeReaction
Removes a reaction from this Message using anEmote
.This message instance will not be updated by this operation.
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/emote.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.Unicode emojis are not included as
Emote
!The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emote 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.
- Parameters:
emote
- TheEmote
to remove as a reaction from this Message.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
IllegalArgumentException
-- If the provided
Emote
is null. - If the provided
Emote
cannot be used in the current channel. SeeEmote.canInteract(User, MessageChannel)
orEmote.canInteract(Member)
for more information.
- If the provided
IllegalStateException
- If this is an ephemeral message- Since:
- 4.1.0
-
removeReaction
@Nonnull @CheckReturnValue RestAction<Void> removeReaction(@Nonnull Emote emote, @Nonnull User user) Removes aUser's
reaction from this Message using anEmote
.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 emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/emote.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.Unicode emojis are not included as
Emote
!The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
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 theTextChannel
when removing the reaction.UNKNOWN_EMOJI
The provided emote 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.
- Parameters:
emote
- TheEmote
to remove as a reaction from this Message.user
- TheUser
to remove the reaction for.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
.IllegalArgumentException
-- If the provided
Emote
is null. - If the provided
Emote
cannot be used in the current channel. SeeEmote.canInteract(User, MessageChannel)
orEmote.canInteract(Member)
for more information. - If the provided user is null
- If the provided
IllegalStateException
-- Since:
- 4.1.0
-
removeReaction
Removes a reaction from this Message using a unicode emoji.
A reference of unicode emojis can be found here: Emoji Table.This message instance will not be updated by this operation.
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/unicode.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.Examples
// custom
message.removeReaction("minn:245267426227388416").queue();
// unicode escape
message.removeReaction("\uD83D\uDE02").queue();
// codepoint notation
message.removeReaction("U+1F602").queue();The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
unicode
- The unicode emoji to add as a reaction to this Message.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
IllegalArgumentException
- If the provided unicode emoji is null or empty.IllegalStateException
- If this is an ephemeral message- Since:
- 4.1.0
-
removeReaction
@Nonnull @CheckReturnValue RestAction<Void> removeReaction(@Nonnull String unicode, @Nonnull User user) Removes a reaction from this Message using a unicode emoji.
A reference of unicode emojis can be found here: Emoji Table.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 emoji/emotes below a message that have a counter beside them showing how many users have reacted with the same emoji/unicode.
Neither success nor failure of this request will affect this Message's
getReactions()
return as Message is immutable.The following
ErrorResponses
are possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theTextChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableMISSING_PERMISSIONS
The reaction request was attempted after the account lostPermission.MESSAGE_MANAGE
in theTextChannel
when removing the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
unicode
- The unicode emoji to add as a reaction to this Message.user
- TheUser
to remove the reaction for.- Returns:
RestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not haveIllegalArgumentException
- If the provided unicode emoji is null or empty or if the provided user is null.IllegalStateException
- If this message:- Since:
- 4.1.0
-
retrieveReactionUsers
This obtains theusers
who reacted using the givenemote
.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 theTextChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided emote 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.
- Parameters:
emote
- Theemote
to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emote's users. - Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
in the channel.IllegalArgumentException
- If the providedEmote
is null.IllegalStateException
- If this Message is ephemeral- Since:
- 4.1.0
-
retrieveReactionUsers
This obtains theusers
who reacted using the given unicode emoji.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 theTextChannel
due toPermission.VIEW_CHANNEL
being revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORY
UNKNOWN_EMOJI
The provided unicode character does not refer to a known emoji unicode character.
Proper unicode characters for emojis can be found here: Emoji TableUNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
unicode
- The unicode emote to retrieve users for.- Returns:
- The
ReactionPaginationAction
of the emoji's users. - Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the logged in account does not havePermission.MESSAGE_HISTORY
in the channel.IllegalArgumentException
- If the provided unicode emoji is null or empty.IllegalStateException
- If this Message is ephemeral- Since:
- 4.1.0
-
getReactionByUnicode
@Nullable @CheckReturnValue MessageReaction.ReactionEmote getReactionByUnicode(@Nonnull String unicode) This obtains theReactionEmote
for the given unicode reaction on this message.Messages also store reactions using unicode values.
An instance of the related
ReactionEmote
can be obtained through this method by using the emoji's unicode value.- Parameters:
unicode
- The unicode value of the reaction emoji.- Returns:
- The
ReactionEmote
of this message or null if not present. - Throws:
UnsupportedOperationException
- If this is a system messageIllegalArgumentException
- If the provided unicode value is null or empty.- Since:
- 4.1.0
-
getReactionById
This obtains theReactionEmote
for the given reaction id on this message.Messages store reactions by keeping a list of reaction names.
An instance of the related
ReactionEmote
can be obtained through this method by using the emote's id.- Parameters:
id
- The string id of the reaction emote.- Returns:
- The
ReactionEmote
of this message or null if not present. - Throws:
UnsupportedOperationException
- If this is a system messageIllegalArgumentException
- If the provided id is not a valid snowflake.- Since:
- 4.1.0
-
getReactionById
This obtains theReactionEmote
for the given reaction id on this message.Messages store reactions by keeping a list of reaction names.
An instance of the related
ReactionEmote
can be obtained through this method by using the emote's id.- Parameters:
id
- The long id of the reaction emote.- Returns:
- The
ReactionEmote
of this message or null if not present. - Throws:
UnsupportedOperationException
- If this is a system message- Since:
- 4.1.0
-
suppressEmbeds
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 theTextChannel
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 theTextChannel
when adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
suppressed
- Whether or not the embed should be suppressed- Returns:
AuditableRestAction
- Type:Void
- Throws:
UnsupportedOperationException
- If this is a system messageInsufficientPermissionException
- If the MessageChannel this message was sent in was aTextChannel
and the currently logged in account does not havePermission.MESSAGE_MANAGE
in the channel.PermissionException
- If the MessageChannel this message was sent in was aPrivateChannel
and the message was not sent by the currently logged in account.IllegalStateException
- If this Message is ephemeral- See Also:
-
crosspost
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 theTextChannel
MISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGE
in the TextChannel.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.
- Returns:
RestAction
- Type:Message
- Throws:
UnsupportedOperationException
- If this is a system messageIllegalStateException
-- If the channel is not a
NewsChannel
. - If the message is ephemeral.
- If the channel is not a
InsufficientPermissionException
- If the currently logged in account does not havePermission.VIEW_CHANNEL
in this channel or if this message is from another user and we don't havePermission.MESSAGE_MANAGE
.- Since:
- 4.2.1
-
isSuppressedEmbeds
boolean isSuppressedEmbeds()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
- Returns:
- Whether or not Embeds are suppressed for this Message.
- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getFlags
Returns an EnumSet of allMessageFlags
present for this Message.- Returns:
- Never-Null EnumSet of present
MessageFlags
- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
getFlagsRaw
long getFlagsRaw()Returns the raw message flags of this message- Returns:
- The raw message flags
- Throws:
UnsupportedOperationException
- If this is a system message- See Also:
-
isEphemeral
boolean isEphemeral()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 ifgetFlags()
containsMessage.MessageFlag.EPHEMERAL
- Returns:
- Whether the message is ephemeral
- Throws:
UnsupportedOperationException
- If this is a system message
-
getType
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
.- Returns:
- The
MessageType
of this message. - Throws:
UnsupportedOperationException
- If this is a system message
-
getInteraction
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.
- Returns:
- The
Interaction
of this message. - Throws:
UnsupportedOperationException
- If this is a system message
-
createThreadChannel
-