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 2 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 theMessageTypeenum.
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 extends Formattable 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:
-
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
Nested ClassesModifier and TypeInterfaceDescriptionstatic classRepresents aMessagefile attachment.static classRepresents anInteractionprovided with aMessage.static enumMention constants, useful for use withPatternsstatic enumEnum representing the flags on a Message. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternPattern used to find instant invites in strings.static final StringTemplate forgetJumpUrl().static final PatternPattern used to findJump URLsin strings.static final intThe maximum amount ofLayoutComponentsthat can be added to a message (5)static final intThe maximum amount of characters sendable in one message.static final intThe maximum amount of Embeds that can be added to one message (10)static final intThe maximum amount of files sendable within a single message (10)static final intThe maximum sendable file size (10 MiB)static final intThe maximum character length for anonce(25)static final intThe maximum amount of reactions that can be added to one message (20)static final intThe maximum amount ofStickersthat can be added to a message (3) -
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, publicThreadChannelspawning/starting at thisMessageinside theIThreadContainerthis 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 data) Edits this message using the providedMessageEditData.editMessageAttachments(Collection<? extends AttachedFile> attachments) Edits this message using the provided files.default MessageEditActioneditMessageAttachments(AttachedFile... attachments) Edits this message using the provided files.editMessageComponents(Collection<? extends LayoutComponent> components) Edits this message using the providedLayoutComponents.default MessageEditActioneditMessageComponents(LayoutComponent... components) Edits this message using the providedLayoutComponents.editMessageEmbeds(Collection<? extends MessageEmbed> embeds) Edits this message using the providedMessageEmbeds.default MessageEditActioneditMessageEmbeds(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.default MessageCreateActionforwardTo(MessageChannel channel) Forwards this message into the provided channel.Rows of interactive components such asButtons.AMessageActivitythat contains its type and party id.default StringIf this message is from an application-ownedWebhookor is a response to anInteraction, this will return the application's id.longIf this message is from an application-ownedWebhookor is a response to anInteraction, this will return the application's id.intReturns the approximate position of this message in aThreadChannel.@Unmodifiable List<Message.Attachment>An immutable list ofAttachmentsthat are attached to this message.The author of this Messagedefault ButtongetButtonById(String id) Gets theButtonwith the specified ID.AllButtonsattached to this message.getButtonsByLabel(String label, boolean ignoreCase) AllButtonswith the specified label attached to this message.TheCategorythis message was sent in.Returns theMessageChannelthat this message was sent in.default StringThe ID for the channel this message was sent in.longThe ID for the channel this message was sent in.Gets theChannelTypethat this message was received from.@Unmodifiable List<LayoutComponent>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 usinggetContentDisplay()and then strips it of markdown characters like *, **, __, ~~, || that provide text formatting.@Unmodifiable List<MessageEmbed>An immutable list ofMessageEmbedsthat are part of this Message.getFlags()Returns an EnumSet of allMessageFlagspresent for this Message.longReturns the raw message flags of this messagegetGuild()Returns theGuildthat this message was sent in.Returns theGuildMessageChannelthat this message was sent in if it was sent in a Guild.default StringThe ID for the guild this message was sent in.longThe ID for the guild this message was sent in.This is sent on the message object when the message is a response to anInteractionwithout an existing message.Creates an immutable List ofInvitecodes that are included in this Message.getJDA()Returns theJDAinstance related to this Message.Returns the jump-to URL for the received message.Returns the author of this Message as amember.TheMentionsused in this message.Returns theMessageReferencefor this Message.@Unmodifiable List<MessageSnapshot>TheMessageSnaphotsattached 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()TheMessagePollattached to this message.getReaction(Emoji emoji) This obtains theMessageReactionfor the givenEmojion this message.@Unmodifiable List<MessageReaction>AllMessageReactionsthat are on this Message.default MessageReferenced message.Returns a possiblynullThreadChannelthat was started from this message.@Unmodifiable List<StickerItem>AllStickerItemsthat are in this Message.Provides theOffsetDateTimedefining when this Message was last edited.getType()This specifies theMessageTypeof this Message.booleanWhether this message instance has an availablegetChannel().booleanhasGuild()Whether this message instance provides a guild instance viagetGuild().booleanisEdited()Returns whether or not this Message has been edited before.booleanWhether this message is ephemeral.booleanWhether this message was sent in aGuild.booleanisFromType(ChannelType type) Used to determine if this Message was received from aMessageChannelof theChannelTypespecified.booleanisPinned()Whether or not this Message has been pinned in its parent channel.booleanWhether embeds are suppressed for this message.booleanWhether this message is silent.booleanisTTS()Defines whether or not this Message triggers TTS (Text-To-Speech).booleanWhether this message is a voice message.booleanpin()Used to add the Message to theMessageChannel'spinned message list.removeReaction(Emoji emoji) Removes own reaction from this Message using anEmoji, you can useremoveReaction(Emoji, User)to remove reactions from other users, orclearReactions(Emoji)to remove all reactions for the specified emoji.removeReaction(Emoji emoji, User user) default MessageCreateActionreply(CharSequence content) Shortcut forgetChannel().sendMessage(content).setMessageReference(this).default MessageCreateActionreply(MessageCreateData msg) Shortcut forgetChannel().sendMessage(data).setMessageReference(this).default MessageCreateActionreplyComponents(Collection<? extends LayoutComponent> components) Shortcut forgetChannel().sendMessageComponents(components).setMessageReference(this).default MessageCreateActionreplyComponents(LayoutComponent component, LayoutComponent... other) Shortcut forgetChannel().sendMessageComponents(component, other).setMessageReference(this).default MessageCreateActionreplyEmbeds(Collection<? extends MessageEmbed> embeds) Shortcut forgetChannel().sendMessageEmbeds(embeds).setMessageReference(this).default MessageCreateActionreplyEmbeds(MessageEmbed embed, MessageEmbed... other) Shortcut forgetChannel().sendMessageEmbeds(embed, other).setMessageReference(this).default MessageCreateActionreplyFiles(Collection<? extends FileUpload> files) Shortcut forgetChannel().sendFiles(files).setMessageReference(this).default MessageCreateActionreplyFiles(FileUpload... files) Shortcut forgetChannel().sendFiles(files).setMessageReference(this).default MessageCreateActionreplyFormat(String format, Object... args) Shortcut forgetChannel().sendMessageFormat(format, args).setMessageReference(this).default MessageCreateActionreplyPoll(MessagePollData poll) Shortcut forgetChannel().sendMessagePoll(data).setMessageReference(this).default MessageCreateActionreplyStickers(Collection<? extends StickerSnowflake> stickers) Replies and references this message.default MessageCreateActionreplyStickers(StickerSnowflake... stickers) Replies and references this message.default PollVotersPaginationActionretrievePollVoters(long answerId) Paginate the users who voted for a poll answer.retrieveReactionUsers(Emoji emoji) static voidSuppresses the warning for missing theMESSAGE_CONTENTintent and using one of the dependent getters.suppressEmbeds(boolean suppressed) Enables/Disables suppression of Embeds on this Message.unpin()Used to remove the Message from theMessageChannel'spinned message list.Methods inherited from interface java.util.Formattable
formatToMethods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
Field Details
-
JUMP_URL
Template forgetJumpUrl().- See Also:
-
MAX_FILE_SIZE
static final int MAX_FILE_SIZEThe maximum sendable file size (10 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)- See Also:
-
MAX_EMBED_COUNT
static final int MAX_EMBED_COUNTThe maximum amount of Embeds that can be added to one message (10) -
MAX_STICKER_COUNT
static final int MAX_STICKER_COUNTThe maximum amount ofStickersthat can be added to a message (3) -
MAX_COMPONENT_COUNT
static final int MAX_COMPONENT_COUNTThe maximum amount ofLayoutComponentsthat can be added to a message (5)- See Also:
-
MAX_NONCE_LENGTH
static final int MAX_NONCE_LENGTHThe maximum character length for anonce(25)- See Also:
-
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 URLsin strings.Groups
You can use the names withIndex 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
-
suppressContentIntentWarning
static void suppressContentIntentWarning()Suppresses the warning for missing theMESSAGE_CONTENTintent and using one of the dependent getters. -
getMessageReference
Returns theMessageReferencefor 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
typeof message. Usually, this is aINLINE_REPLYreference. 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:
-
getMentions
TheMentionsused in this message.This includes
Members,GuildChannels,Roles, andCustomEmojis. Can also be used to check if a message mentions@everyoneor@here.Example
System.out.println("Message mentioned these users: " + message.getMentions().getUsers()); System.out.println("Message used these custom emojis: " + message.getMentions().getCustomEmojis());- Returns:
Mentionsfor this message.
-
isEdited
boolean isEdited()Returns whether or not this Message has been edited before.- Returns:
- True if this message has been edited.
-
getTimeEdited
Provides theOffsetDateTimedefining 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
nullif the Message has never been edited.
-
getAuthor
The author of this Message- Returns:
- Message author
-
getMember
Returns the author of this Message as amember.
This is only valid if the Message was actually sent in a GuildMessageChannel. This will returnnullif the message was not sent in a GuildMessageChannel, 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
RestActionsof 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
nullif the message was not sent in a GuildMessageChannel, or if the message was sent by a Webhook. - See Also:
-
getApproximatePosition
int getApproximatePosition()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.
- Returns:
- The approximate position of this message, or
-1if this message is too old. - Throws:
IllegalStateException- If this message was not sent in aThreadChannel.- 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
-
getContentDisplay
The textual content of this message in the format that would be shown to the Discord client. AllIMentionableentities will be resolved to the format shown by the Discord client instead of the <id> format.This includes resolving:
Users/Membersto their @Username/@Nickname format,GuildChannelsto their #ChannelName format,Rolesto their @RoleName formatCustom Emojis(not unicode emojis!) to their:name:format.If you want the actual Content (mentions as <@id>), use
getContentRaw()insteadRequires
GatewayIntent.MESSAGE_CONTENT- Returns:
- The textual content of the message with mentions resolved to be visually like the Discord client.
-
getContentRaw
The raw textual content of this message. Does not resolveIMentionableentities 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.Requires
GatewayIntent.MESSAGE_CONTENT- 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.Requires
GatewayIntent.MESSAGE_CONTENT- Returns:
- The textual content from
getContentDisplay()with all text formatting characters removed or escaped.
-
getInvites
Creates an immutable List ofInvitecodes that are included in this Message.
This will use thePatternprovided underINVITE_PATTERNto construct aMatcherthat 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
-
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 useMessageCreateAction.setNonce(String)!- Returns:
- The validation nonce
- See Also:
-
isFromType
Used to determine if this Message was received from aMessageChannelof theChannelTypespecified.Useful for restricting functionality to a certain type of channels.
- Parameters:
type- TheChannelTypeto check against.- Returns:
- True if the
ChannelTypewhich this message was received from is the same as the one specified bytype.
-
isFromGuild
boolean isFromGuild()Whether this message was sent in aGuild.
If this isfalsethengetGuild()will throw anIllegalStateException.- Returns:
- True, if
getChannelType().isGuild()is true.
-
getChannelType
Gets theChannelTypethat this message was received from.- Returns:
- The ChannelType which this message was received from.
-
isWebhookMessage
boolean isWebhookMessage()Indicates if this Message was sent by aWebhookinstead of aUser.
Useful if you want to ignore non-users.- Returns:
- True if this message was sent by a
Webhook.
-
getApplicationId
If this message is from an application-ownedWebhookor is a response to anInteraction, this will return the application's id.- Returns:
- The application's id or
nullif this message was not sent by an application
-
getApplicationIdLong
long getApplicationIdLong()If this message is from an application-ownedWebhookor is a response to anInteraction, this will return the application's id.- Returns:
- The application's id or 0 if this message was not sent by an application
-
hasChannel
boolean hasChannel()Whether this message instance has an availablegetChannel().This can be
falsefor messages sent via webhooks, or in the context of interactions.- Returns:
- True, if
getChannel()is available
-
getChannelIdLong
long getChannelIdLong()The ID for the channel this message was sent in.
This is useful whengetChannel()is unavailable, for instance on webhook messages.- Returns:
- The channel id
-
getChannelId
The ID for the channel this message was sent in.
This is useful whengetChannel()is unavailable, for instance on webhook messages.- Returns:
- The channel id
-
getChannel
Returns theMessageChannelthat this message was sent in.- Returns:
- The MessageChannel of this Message
- Throws:
IllegalStateException- If the channel is not available (seehasChannel())- See Also:
-
getGuildChannel
Returns theGuildMessageChannelthat this message was sent in if it was sent in a Guild.- Returns:
- The MessageChannel of this Message
- Throws:
IllegalStateException- If this was not sent in aGuildor the channel is not available (seehasChannel()).- See Also:
-
getCategory
TheCategorythis message was sent in. This will always benullfor DMs.
Equivalent togetGuildChannel().getParentCategory()if this was sent in aGuildMessageChannel.- Returns:
Categoryfor this message
-
hasGuild
boolean hasGuild()Whether this message instance provides a guild instance viagetGuild().
This is different fromisFromGuild(), which checks whether the message was sent in a guild. This method describes whethergetGuild()is usable.This can be
falsefor messages sent via webhooks, or in the context of interactions.- Returns:
- True, if
getGuild()is provided
-
getGuildIdLong
long getGuildIdLong()The ID for the guild this message was sent in.
This is useful whengetGuild()is not provided, for instance on webhook messages.- Returns:
- The guild id, or 0 if this message was not sent in a guild
-
getGuildId
The ID for the guild this message was sent in.
This is useful whengetGuild()is not provided, for instance on webhook messages.- Returns:
- The guild id, or null if this message was not sent in a guild
-
getGuild
Returns theGuildthat this message was sent in.
This is just a shortcut togetGuildChannel().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 usingisFromType(ChannelType)orgetChannelType().- Returns:
- The Guild this message was sent in
- Throws:
IllegalStateException- If this was not sent in aGuildChannelor the guild instance is not provided- See Also:
-
getAttachments
An immutable list ofAttachmentsthat are attached to this message.
Most likely this will only ever be 1Attachmentat most.Requires
GatewayIntent.MESSAGE_CONTENT- Returns:
- Immutable list of
Attachments.
-
getEmbeds
An immutable list ofMessageEmbedsthat are part of this Message.Requires
GatewayIntent.MESSAGE_CONTENT- Returns:
- Immutable list of all given MessageEmbeds.
-
getComponents
Layouts of interactive components, usuallyActionRows.
You can useMessageRequest.setComponents(LayoutComponent...)to update these.Requires
GatewayIntent.MESSAGE_CONTENT- Returns:
- Immutable
ListofLayoutComponent - See Also:
-
getPoll
TheMessagePollattached to this message.- Returns:
- Possibly-null poll instance for this message
- See Also:
-
endPoll
End the poll attached to this message.- Returns:
AuditableRestAction- Type:Message- Throws:
IllegalStateException- If this poll was not sent by the currently logged in account or no poll was attached to this message
-
retrievePollVoters
Paginate the users who voted for a poll answer.- Parameters:
answerId- The id of the poll answer, usually the ordinal position of the answer (first is 1)- Returns:
PollVotersPaginationAction
-
getActionRows
Rows of interactive components such asButtons.
You can useMessageRequest.setComponents(LayoutComponent...)to update these.Requires
GatewayIntent.MESSAGE_CONTENT -
getButtons
AllButtonsattached to this message.Requires
GatewayIntent.MESSAGE_CONTENT -
getButtonById
Gets theButtonwith the specified ID.Requires
GatewayIntent.MESSAGE_CONTENT- Parameters:
id- The id of the button- Returns:
- The
Buttonor null if no button with that ID is present on this message - Throws:
IllegalArgumentException- If the id is null
-
getButtonsByLabel
@Nonnull default @Unmodifiable List<Button> getButtonsByLabel(@Nonnull String label, boolean ignoreCase) AllButtonswith the specified label attached to this message.Requires
GatewayIntent.MESSAGE_CONTENT- Parameters:
label- The button labelignoreCase- Whether to useString.equalsIgnoreCase(String)instead ofString.equals(Object)- Returns:
- Immutable
ListofButtonswith the specified label - Throws:
IllegalArgumentException- If the provided label is null
-
getReactions
AllMessageReactionsthat are on this Message.- Returns:
- Immutable list of all MessageReactions on this message.
- See Also:
-
getStickers
AllStickerItemsthat are in this Message.
The returned StickerItems may only contain necessary information such as the sticker id, format type, name, and icon url.- Returns:
- Immutable list of all StickerItems in this message.
-
getMessageSnapshots
TheMessageSnaphotsattached 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.
- Returns:
- Immutable
ListofMessageSnapshot
-
isTTS
boolean isTTS()Defines whether or not this Message triggers TTS (Text-To-Speech).- Returns:
- If this message is TTS.
-
getActivity
AMessageActivitythat contains its type and party id.- Returns:
- The activity, or
nullif no activity was added to the message.
-
editMessage
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
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
newContent- The new content of the message, or empty string to remove content (assumes other fields exist like embeds)- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException- If null is provided or the new content is longer than 2000 characters- See Also:
-
editMessage
Edits this message using the providedMessageEditData.
You can useMessageEditBuilderto create aMessageEditDatainstance.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
data- TheMessageEditDataused to update the message- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException- If null is provided- See Also:
-
editMessageEmbeds
@Nonnull @CheckReturnValue MessageEditAction editMessageEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Edits this message using the providedMessageEmbeds.
You can useEmbedBuilderto create aMessageEmbedinstance.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
embeds- The newMessageEmbedsof the message, empty list to remove embeds- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException-- If
nullis provided - If more than 10 embeds are provided
- If
- See Also:
-
editMessageEmbeds
@Nonnull @CheckReturnValue default MessageEditAction editMessageEmbeds(@Nonnull MessageEmbed... embeds) Edits this message using the providedMessageEmbeds.
You can useEmbedBuilderto create aMessageEmbedinstance.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
embeds- The newMessageEmbedsof the message, or an empty list to remove all embeds- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException-- If
nullis provided - If more than 10 embeds are provided
- If
- See Also:
-
editMessageComponents
@Nonnull @CheckReturnValue MessageEditAction editMessageComponents(@Nonnull Collection<? extends LayoutComponent> components) Edits this message using the providedLayoutComponents.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
components- The newLayoutComponentsof the message, or an empty list to remove all components- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException-- If
nullis provided - If any of the components is not
message compatible - If more than 5 components are provided
- If
- See Also:
-
editMessageComponents
@Nonnull @CheckReturnValue default MessageEditAction editMessageComponents(@Nonnull LayoutComponent... components) Edits this message using the providedLayoutComponents.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
components- The newLayoutComponentsof the message, empty list to remove all components- Returns:
MessageEditAction- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException-- If
nullis provided - If any of the components is not
message compatible - If more than 5 components are provided
- If
- See Also:
-
editMessageFormat
@Nonnull @CheckReturnValue MessageEditAction editMessageFormat(@Nonnull String format, @Nonnull Object... args) Edits this message using the provided format arguments.The following
ErrorResponsesare possible:MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.
- Parameters:
format- Format String used to generate new Contentargs- The arguments which should be used to format the given format String- Returns:
MessageEditAction- Throws:
IllegalArgumentException- If providedformatisnullor blank.UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botInsufficientPermissionException- If this is aGuildMessageChanneland this account does not havePermission.VIEW_CHANNELIllegalFormatException- 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.- See Also:
-
editMessageAttachments
@Nonnull @CheckReturnValue MessageEditAction editMessageAttachments(@Nonnull Collection<? extends AttachedFile> attachments) Edits this message using the provided files.The following
ErrorResponsesare 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 theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
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.- Parameters:
attachments- The new attachments of the message (Can beFileUploadsorAttachmentUpdates)- Returns:
MessageEditActionthat can be used to further update the message- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException- Ifnullis provided- See Also:
-
editMessageAttachments
@Nonnull @CheckReturnValue default MessageEditAction editMessageAttachments(@Nonnull AttachedFile... attachments) Edits this message using the provided files.The following
ErrorResponsesare 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 theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildMessageChannelUNKNOWN_MESSAGE
The providedmessageIdis 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.UNKNOWN_CHANNEL
The request was attempted after the channel was deleted.
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.- Parameters:
attachments- The new attachments of the message (Can beFileUploadsorAttachmentUpdates)- Returns:
MessageEditActionthat can be used to further update the message- Throws:
UnsupportedOperationException- If this is a system messageIllegalStateException- If the message is not authored by this botIllegalArgumentException- Ifnullis provided- See Also:
-
replyStickers
@Nonnull @CheckReturnValue default MessageCreateAction replyStickers(@Nonnull Collection<? extends StickerSnowflake> stickers) Replies and references this message.
This is identical tomessage.getGuildChannel().sendStickers(stickers).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 withMessageCreateAction.failOnInvalidReply(boolean).For further info, see
GuildMessageChannel.sendStickers(Collection)andMessageCreateAction.setMessageReference(Message).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
stickers- The 1-3 stickers to send- Returns:
MessageCreateAction- Throws:
MissingAccessException- If the currently logged in account does not havePermission.VIEW_CHANNELin this channelInsufficientPermissionException-- If this is a
ThreadChanneland the bot does not havePermission.MESSAGE_SEND_IN_THREADS - If this is not a
ThreadChanneland the bot does not havePermission.MESSAGE_SEND
- If this is a
IllegalArgumentException-- If any of the provided stickers is a
GuildSticker, which is eitherunavailableor from a different guild. - If the list is empty or has more than 3 stickers
- If null is provided
- If any of the provided stickers is a
IllegalStateException- If this message was not sent in aGuild- See Also:
-
replyStickers
@Nonnull @CheckReturnValue default MessageCreateAction replyStickers(@Nonnull StickerSnowflake... stickers) Replies and references this message.
This is identical tomessage.getGuildChannel().sendStickers(stickers).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 withMessageCreateAction.failOnInvalidReply(boolean).For further info, see
GuildMessageChannel.sendStickers(Collection)andMessageCreateAction.setMessageReference(Message).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
stickers- The 1-3 stickers to send- Returns:
MessageCreateAction- Throws:
MissingAccessException- If the currently logged in account does not havePermission.VIEW_CHANNELin this channelInsufficientPermissionException-- If this is a
ThreadChanneland the bot does not havePermission.MESSAGE_SEND_IN_THREADS - If this is not a
ThreadChanneland the bot does not havePermission.MESSAGE_SEND
- If this is a
IllegalArgumentException-- If any of the provided stickers is a
GuildSticker, which is eitherunavailableor from a different guild. - If the list is empty or has more than 3 stickers
- If null is provided
- If any of the provided stickers is a
IllegalStateException- If this message was not sent in aGuild- See Also:
-
reply
Shortcut forgetChannel().sendMessage(content).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
content- The reply content- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessage(CharSequence)throwsIllegalArgumentException- IfMessageChannel.sendMessage(CharSequence)throws
-
reply
Shortcut forgetChannel().sendMessage(data).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
msg- TheMessageCreateDatato send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessage(MessageCreateData)throwsIllegalArgumentException- IfMessageChannel.sendMessage(MessageCreateData)throws
-
replyPoll
Shortcut forgetChannel().sendMessagePoll(data).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_CHANNEL
if this channel was deletedCANNOT_SEND_TO_USER
If this is aPrivateChanneland the currently logged in account does not share any Guilds with the recipient UserMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filterPOLL_INVALID_CHANNEL_TYPE
This channel does not allow pollsPOLL_WITH_UNUSABLE_EMOJI
This poll uses an external emoji that the bot is not allowed to use
- Parameters:
poll- The poll to send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessage(MessageCreateData)throwsIllegalArgumentException- IfMessageChannel.sendMessage(MessageCreateData)throws
-
replyEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction replyEmbeds(@Nonnull MessageEmbed embed, @Nonnull MessageEmbed... other) Shortcut forgetChannel().sendMessageEmbeds(embed, other).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
embed- TheMessageEmbedto sendother- Any additionMessageEmbedsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessageEmbeds(MessageEmbed, MessageEmbed...)throwsIllegalArgumentException- IfMessageChannel.sendMessageEmbeds(MessageEmbed, MessageEmbed...)throws
-
replyEmbeds
@Nonnull @CheckReturnValue default MessageCreateAction replyEmbeds(@Nonnull Collection<? extends MessageEmbed> embeds) Shortcut forgetChannel().sendMessageEmbeds(embeds).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
embeds- TheMessageEmbedsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessageEmbeds(Collection)throwsIllegalArgumentException- IfMessageChannel.sendMessageEmbeds(Collection)throws
-
replyComponents
@Nonnull @CheckReturnValue default MessageCreateAction replyComponents(@Nonnull LayoutComponent component, @Nonnull LayoutComponent... other) Shortcut forgetChannel().sendMessageComponents(component, other).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
component- TheLayoutComponentto sendother- Any additionLayoutComponentsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessageComponents(LayoutComponent, LayoutComponent...)throwsIllegalArgumentException- IfMessageChannel.sendMessageComponents(LayoutComponent, LayoutComponent...)throws
-
replyComponents
@Nonnull @CheckReturnValue default MessageCreateAction replyComponents(@Nonnull Collection<? extends LayoutComponent> components) Shortcut forgetChannel().sendMessageComponents(components).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
components- TheLayoutComponentsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessageComponents(Collection)throwsIllegalArgumentException- IfMessageChannel.sendMessageComponents(Collection)throws
-
replyFormat
@Nonnull @CheckReturnValue default MessageCreateAction replyFormat(@Nonnull String format, @Nonnull Object... args) Shortcut forgetChannel().sendMessageFormat(format, args).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
format- The format stringargs- The arguments to use in the format string- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendMessageFormat(String, Object...)throwsIllegalArgumentException- IfMessageChannel.sendMessageFormat(String, Object...)throws
-
replyFiles
Shortcut forgetChannel().sendFiles(files).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
files- TheFileUploadsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendFiles(FileUpload...)throwsIllegalArgumentException- IfMessageChannel.sendFiles(FileUpload...)throws
-
replyFiles
@Nonnull @CheckReturnValue default MessageCreateAction replyFiles(@Nonnull Collection<? extends FileUpload> files) Shortcut forgetChannel().sendFiles(files).setMessageReference(this).Possible
ErrorResponsesinclude:UNKNOWN_MESSAGE
If this message no longer existsMESSAGE_BLOCKED_BY_AUTOMOD
If this message was blocked by anAutoModRuleMESSAGE_BLOCKED_BY_HARMFUL_LINK_FILTER
If this message was blocked by the harmful link filter
- Parameters:
files- TheFileUploadsto send- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- IfMessageChannel.sendFiles(Collection)throwsIllegalArgumentException- IfMessageChannel.sendFiles(Collection)throws
-
forwardTo
Forwards this message into the provided channel.A message forward request cannot contain additional content.
Possible
ErrorResponsesfrom forwarding include:REFERENCED_MESSSAGE_NOT_FOUND
If the provided reference cannot be resolved to a messageFORWARD_CANNOT_HAVE_CONTENT
If additional content is sent alongside a forwarded message
- Parameters:
channel- The target channel to forward to- Returns:
MessageCreateAction- Throws:
InsufficientPermissionException- If the bot is missingPermission.MESSAGE_SENDin the target channelIllegalArgumentException- If the target channel is null
-
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 aGuildChanneland the current account hasPermission.MESSAGE_MANAGEin the channel.To delete many messages at once in a
MessageChannelyou should useMessageChannel.purgeMessages(List)instead.The following
ErrorResponsesare possible:MISSING_ACCESS
The delete was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked, or the account lost access to theGuildtypically due to being kicked or removed.MISSING_PERMISSIONS
The delete was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannelwhen 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:
MissingAccessException- If the currently logged in account does not haveaccessin this channel.InsufficientPermissionException- If this Message was not sent by the currently logged in account, the Message was sent in aGuildChannel, and the currently logged in account does not havePermission.MESSAGE_MANAGEin the channel.IllegalStateException-- If this Message was not sent by the currently logged in account and it was not sent in a
GuildChannel. - If this Message is ephemeral
- If this message type cannot be deleted. (See
MessageType.canDelete())
- If this Message was not sent by the currently logged in account and it was not sent in a
- See Also:
-
getJDA
Returns theJDAinstance related to this Message.- Returns:
- the corresponding JDA instance
-
isPinned
boolean isPinned()Whether or not this Message has been pinned in its parent channel.- Returns:
- True - if this message has been pinned.
-
pin
Used to add the Message to theMessageChannel'spinned 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
ErrorResponsesare possible:MISSING_ACCESS
The pin request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked, or the account lost access to theGuildtypically due to being kicked or removed.MISSING_PERMISSIONS
The pin request was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction- Type:Void- Throws:
InsufficientPermissionException- If this Message is from aGuildChanneland:- 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'spinned 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
ErrorResponsesare possible:MISSING_ACCESS
The unpin request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked, or the account lost access to theGuildtypically due to being kicked or removed.MISSING_PERMISSIONS
The unpin request was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannel.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction- Type:Void- Throws:
InsufficientPermissionException- If this Message is from aGuildChanneland:- 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 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
getReactions()return as Message is immutable.The following
ErrorResponsesare possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORYREACTION_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_REACTIONorPermission.MESSAGE_HISTORYin theGuildChannelwhen 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.
- Parameters:
emoji- TheEmojito add as a reaction to this Message.- Returns:
RestAction- Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the logged in account does not haveIllegalArgumentException-- If the provided
Emojiis null. - If the provided
Emojiis a custom emoji and cannot be used in the current channel. SeeRichCustomEmoji.canInteract(User, MessageChannel)orRichCustomEmoji.canInteract(Member)for more information.
- If the provided
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
ErrorResponsesare possible:MISSING_ACCESS
The clear-reactions request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked, or the account lost access to theGuildtypically due to being kicked or removed.MISSING_PERMISSIONS
The clear-reactions request was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannelwhen adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Returns:
RestAction- Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the currently logged in account does not havePermission.MESSAGE_MANAGEin 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 specifiedEmoji.Please note that you can't clear reactions if this message was sent in a
PrivateChannel!The following
ErrorResponsesare possible:MISSING_ACCESS
The currently logged in account lost access to the channel by either being removed from the guild or losing theVIEW_CHANNELpermissionUNKNOWN_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.
- Parameters:
emoji- TheEmojito remove reactions for- Returns:
RestAction- Throws:
InsufficientPermissionException- If the currently logged in account does not havePermission.MESSAGE_MANAGEin 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
-
removeReaction
Removes own reaction from this Message using anEmoji, you can useremoveReaction(Emoji, User)to remove reactions from other users, orclearReactions(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
getReactions()return as Message is immutable.The following
ErrorResponsesare possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORYUNKNOWN_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.
- Parameters:
emoji- TheEmojireaction to remove as a reaction from this Message.- Returns:
RestAction- Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the logged in account does not havePermission.MESSAGE_HISTORYIllegalArgumentException-- If the provided
Emojiis null. - If the provided
Emojiis a custom emoji and cannot be used in the current channel. SeeRichCustomEmoji.canInteract(User, MessageChannel)orRichCustomEmoji.canInteract(Member)for more information.
- If the provided
IllegalStateException- If this is an ephemeral message
-
removeReaction
@Nonnull @CheckReturnValue RestAction<Void> removeReaction(@Nonnull Emoji emoji, @Nonnull User user) Removes aUser'sreaction 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
getReactions()return as Message is immutable.The following
ErrorResponsesare possible:MISSING_ACCESS
The reaction request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORYMISSING_PERMISSIONS
The reaction request was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannelwhen 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.
- Parameters:
emoji- TheEmojireaction to remove as a reaction from this Message.user- TheUserto remove the reaction for.- Returns:
RestAction- Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the logged in account does not havePermission.MESSAGE_HISTORY.IllegalArgumentException-- If the provided
emojiis null. - If the provided
emojicannot be used in the current channel. SeeRichCustomEmoji.canInteract(User, MessageChannel)orRichCustomEmoji.canInteract(Member)for more information. - If the provided user is null
- If the provided
IllegalStateException-
-
retrieveReactionUsers
This obtains theuserswho 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
ReactionPaginationActionof the users who've reacted to this message.The following
ErrorResponsesare possible:MISSING_ACCESS
The retrieve request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked
Also can happen if the account lost thePermission.MESSAGE_HISTORYUNKNOWN_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.
- Parameters:
emoji- TheEmojito retrieve users for.- Returns:
- The
ReactionPaginationActionof the users who reacted with the provided emoji - Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the logged in account does not havePermission.MESSAGE_HISTORYin the channel.IllegalArgumentException- If the providedEmojiis null.IllegalStateException- If this Message is ephemeral
-
getReaction
This obtains theMessageReactionfor the givenEmojion this message.
The reaction instance also store which users reacted with the specified emoji.Messages store reactions by keeping a list of reaction names.
- Parameters:
emoji- The unicode or custom emoji of the reaction emoji- Returns:
- The
MessageReactionor null if not present. - Throws:
IllegalArgumentException- If the provided emoji is null
-
suppressEmbeds
Enables/Disables suppression of Embeds on this Message.
Suppressing Embeds is equivalent to pressing theXin the top-right corner of an Embed inside the Discord client.The following
ErrorResponsesare possible:MISSING_ACCESS
The clear-reactions request was attempted after the account lost access to theGuildChanneldue toPermission.VIEW_CHANNELbeing revoked, or the account lost access to theGuildtypically due to being kicked or removed.MISSING_PERMISSIONS
The suppress-embeds request was attempted after the account lostPermission.MESSAGE_MANAGEin theGuildChannelwhen adding the reaction.UNKNOWN_MESSAGE
If the message has already been deleted. This might also be triggered for ephemeral messages.
- Parameters:
suppressed- Whether the embed should be suppressed- Returns:
AuditableRestAction- Type:Void- Throws:
InsufficientPermissionException- If the MessageChannel this message was sent in was aGuildChanneland the currently logged in account does not havePermission.MESSAGE_MANAGEin the channel.PermissionException- If the MessageChannel this message was sent in was aPrivateChanneland 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
ErrorResponsesare possible:ALREADY_CROSSPOSTED
The target message has already been crossposted.MISSING_ACCESS
The request was attempted after the account lost access to theGuildtypically due to being kicked or removed, or afterPermission.VIEW_CHANNELwas revoked in theGuildChannelMISSING_PERMISSIONS
The request was attempted after the account lostPermission.MESSAGE_MANAGEin 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.
- Returns:
RestAction- Type:Message- Throws:
IllegalStateException-- If the channel is not a
NewsChannel. - If the message is ephemeral.
- If the channel is not a
MissingAccessException- If the currently logged in account does not haveaccessin this channel.InsufficientPermissionException- If the currently logged in account does not havePermission.VIEW_CHANNELin 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.
- See Also:
-
getFlags
Returns an EnumSet of allMessageFlagspresent for this Message.- Returns:
- Never-Null EnumSet of present
MessageFlags - See Also:
-
getFlagsRaw
long getFlagsRaw()Returns the raw message flags of this message- Returns:
- The raw message flags
- 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
-
isSuppressedNotifications
boolean isSuppressedNotifications()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 ifgetFlags()containsMessage.MessageFlag.NOTIFICATIONS_SUPPRESSED- Returns:
- Whether the message is silent
-
isVoiceMessage
boolean isVoiceMessage()Whether this message is a voice message.- Returns:
- True, if this is a voice message
-
getStartedThread
Returns a possiblynullThreadChannelthat was started from this message. This can benulldue to no ThreadChannel being started from it or the ThreadChannel later being deleted.- Returns:
- The
ThreadChannelthat was started from this message.
-
getType
This specifies theMessageTypeof 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 messagesor special messages likewelcome messages.- Returns:
- The
MessageTypeof this message.
-
getInteraction
This is sent on the message object when the message is a response to anInteractionwithout 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
Interactionof this message.
-
createThreadChannel
Creates a new, publicThreadChannelspawning/starting at thisMessageinside theIThreadContainerthis message was sent in.
The starting message will copy this message, and will be of typeMessageType.THREAD_STARTER_MESSAGE.The resulting
ThreadChannelmay be one of:Possible
ErrorResponsescaused by the returnedRestActioninclude 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.
- Parameters:
name- The name of the new ThreadChannel (up to 100 characters)- Returns:
- A specific
ThreadChannelActionthat may be used to configure the new ThreadChannel before its creation. - Throws:
IllegalArgumentException- If the provided name is null, blank, empty, or longer than 100 charactersIllegalStateException- If the message's channel is not actually aIThreadContainer.UnsupportedOperationException- If this is a forum channel. You must usecreateForumPost(...)instead.InsufficientPermissionException- If the bot does not havePermission.CREATE_PUBLIC_THREADSin this channel
-