public interface Message extends ISnowflake, java.util.Formattable
MessageChannels.
Formattable and can be used with a Formatter
such as used by String.format(String, Object...)
or PrintStream.printf(String, Object...).
This will use getContent() rather than Object.toString()!
Supported Features:
getRawContent()
(Example: %#s - uses getContent())%20s - uses at minimum 20 chars;
%-10s - uses left-justified padding)...; Example: %.20s)More information on formatting syntax can be found in the format syntax documentation!
| Modifier and Type | Interface and Description |
|---|---|
static class |
Message.Attachment
Represents a
Message file attachment. |
| Modifier and Type | Field and Description |
|---|---|
static int |
MAX_FILE_SIZE |
| Modifier and Type | Method and Description |
|---|---|
RestAction<java.lang.Void> |
addReaction(Emote emote)
Adds a reaction to this Message using an
Emote. |
RestAction<java.lang.Void> |
addReaction(java.lang.String unicode)
Adds a reaction to this Message using a UTF8 emoji.
|
RestAction<java.lang.Void> |
clearReactions()
Removes all reactions from this Message.
|
AuditableRestAction<java.lang.Void> |
delete()
Deletes this Message from Discord.
|
RestAction<Message> |
editMessage(Message newContent)
Edits this Message's content to the provided
Message. |
RestAction<Message> |
editMessage(MessageEmbed newContent)
Edits this Message's content to the provided
MessageEmbed. |
RestAction<Message> |
editMessage(java.lang.String newContent)
Edits this Message's content to the provided String.
|
RestAction<Message> |
editMessageFormat(java.lang.String format,
java.lang.Object... args)
Edits this Message's content to the provided
MessageEmbed. |
java.util.List<Message.Attachment> |
getAttachments()
An unmodifiable list of
Attachments that are attached to this message. |
User |
getAuthor()
The author of this Message
|
MessageChannel |
getChannel()
Returns the
MessageChannel that this message was sent in. |
ChannelType |
getChannelType()
Gets the
ChannelType that this message was received from. |
java.lang.String |
getContent()
The textual content of this message in the format that would be shown to the Discord client.
|
java.time.OffsetDateTime |
getEditedTime()
Provides the
OffsetDateTime defining when this Message was last
edited. |
java.util.List<MessageEmbed> |
getEmbeds()
An unmodifiable list of
MessageEmbeds that are part of this
Message. |
java.util.List<Emote> |
getEmotes()
All
Emotes used in this Message. |
Group |
getGroup()
Returns the
Group that this message was sent in. |
Guild |
getGuild()
Returns the
Guild that this message was sent in. |
JDA |
getJDA()
Returns the
JDA instance related to this Message. |
Member |
getMember()
Returns the author of this Message as a
member. |
java.util.List<TextChannel> |
getMentionedChannels()
A immutable list of all mentioned
TextChannels. |
java.util.List<Role> |
getMentionedRoles()
A immutable list of all mentioned
Roles. |
java.util.List<User> |
getMentionedUsers()
A immutable list of all mentioned users.
|
PrivateChannel |
getPrivateChannel()
Returns the
PrivateChannel that this message was sent in. |
java.lang.String |
getRawContent()
The raw textual content of this message.
|
java.util.List<MessageReaction> |
getReactions()
All
MessageReactions that are on this Message. |
java.lang.String |
getStrippedContent()
Gets the textual content of this message using
getContent() and then strips it of all markdown characters
like *, **, __, ~~ that provide text formatting. |
TextChannel |
getTextChannel()
Returns the
TextChannel that this message was sent in. |
MessageType |
getType()
This specifies the
MessageType of this Message. |
boolean |
isEdited()
Returns whether or not this Message has been edited before.
|
boolean |
isFromType(ChannelType type)
Used to determine if this Message was received from a
MessageChannel
of the ChannelType specified. |
boolean |
isMentioned(User user)
Checks if given user was mentioned in this message in any way (@User, @everyone, @here).
|
boolean |
isPinned()
Whether or not this Message has been pinned in its parent channel.
|
boolean |
isTTS()
Defines whether or not this Message triggers TTS (Text-To-Speech).
|
boolean |
isWebhookMessage()
|
boolean |
mentionsEveryone()
Indicates if this Message mentions everyone using @everyone or @here.
|
RestAction<java.lang.Void> |
pin()
Used to add the Message to the
MessageChannel's pinned message list. |
RestAction<java.lang.Void> |
unpin()
Used to remove the Message from the
MessageChannel's pinned message list. |
getCreationTime, getId, getIdLongstatic final int MAX_FILE_SIZE
java.util.List<User> getMentionedUsers()
PrivateChannel's, this always returns an empty Listboolean isMentioned(User user)
user - The user to check on.java.util.List<TextChannel> getMentionedChannels()
TextChannels. If none were mentioned, this list is empty.
PrivateChannels and Groups,
this always returns an empty List.java.util.List<Role> getMentionedRoles()
Roles. If none were mentioned, this list is empty.
PrivateChannels and Groups,
this always returns an empty List.boolean mentionsEveryone()
PrivateChannel's, this always returns false.boolean isEdited()
java.time.OffsetDateTime getEditedTime()
OffsetDateTime defining when this Message was last
edited. If this Message has not been edited (isEdited() is false), then this method
will return null.null if the Message has never been edited.User getAuthor()
Member getMember()
member.
getGuild().getMember(getAuthor()).
null
if it was not sent from a TextChannel.
isFromType(ChannelType) or getChannelType().null if the message was not sent from a TextChannel.java.lang.String getContent()
IMentionable 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 format
Emotes (not emojis!) to their :name: format.
If you want the actual Content (mentions as <@id>), use getRawContent() instead
java.lang.String getRawContent()
IMentionable
entities like getContent() 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.java.lang.String getStrippedContent()
getContent() and then strips it of all 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.getContent() with all text formatting characters removed or escaped.boolean isFromType(ChannelType type)
MessageChannel
of the ChannelType specified.
ChannelType.VOICE as Messages can't be sent to
VoiceChannels.
Useful for restricting functionality to a certain type of channels.
type - The ChannelType to check against.ChannelType which this message was received
from is the same as the one specified by type.ChannelType getChannelType()
ChannelType that this message was received from.
ChannelType.VOICE as Messages can't be sent to
VoiceChannels.boolean isWebhookMessage()
Webhook instead of a
User.
Webhook.MessageChannel getChannel()
MessageChannel that this message was sent in.PrivateChannel getPrivateChannel()
PrivateChannel that this message was sent in.
null
if it was not sent from a PrivateChannel.
isFromType(ChannelType) or getChannelType().
Use getChannel() for an ambiguous MessageChannel
if you do not need functionality specific to PrivateChannel.
null if it was not sent from a PrivateChannel.Group getGroup()
Group that this message was sent in.
null
if it was not sent from a Group.
isFromType(ChannelType) or getChannelType().
Use getChannel() for an ambiguous MessageChannel
if you do not need functionality specific to Group.
null if it was not sent from a Group.TextChannel getTextChannel()
TextChannel that this message was sent in.
null
if it was not sent from a TextChannel.
isFromType(ChannelType) or getChannelType().
Use getChannel() for an ambiguous MessageChannel
if you do not need functionality specific to TextChannel.
null if it was not sent from a TextChannel.Guild getGuild()
Guild that this message was sent in.
getTextChannel().getGuild().
null
if it was not sent from a TextChannel.
isFromType(ChannelType) or getChannelType().null if it was not sent from a TextChannel.java.util.List<Message.Attachment> getAttachments()
Attachments that are attached to this message.
Attachment at most.Attachments.java.util.List<MessageEmbed> getEmbeds()
MessageEmbeds that are part of this
Message.java.util.List<Emote> getEmotes()
Emotes used in this Message.
Guild.getEmotes(). These are not the same
as the UTF8 emojis that Discord also supports.
This may or may not contain fake Emotes which means they can be displayed but not used by the logged in account.
To check whether an Emote is fake you can test if IFakeable.isFake() returns true.
Unicode emojis are not included as Emote!
java.util.List<MessageReaction> getReactions()
MessageReactions that are on this Message.boolean isTTS()
@CheckReturnValue RestAction<Message> editMessage(java.lang.String newContent)
The following ErrorResponses are possible:
MISSING_ACCESS
Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_WRITE in
the TextChannel.UNKNOWN_MESSAGE
newContent - the new content of the MessageRestAction - Type: Message
Message with the updated contentjava.lang.IllegalStateException - If the message attempting to be edited was not created by the currently logged in account, or if
newContent's length is 0 or greater than 2000.@CheckReturnValue RestAction<Message> editMessage(MessageEmbed newContent)
MessageEmbed.
The following ErrorResponses are possible:
MISSING_ACCESS
Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_WRITE in
the TextChannel.UNKNOWN_MESSAGE
newContent - the new content of the MessageRestAction - Type: Message
Message with the updated contentjava.lang.IllegalStateException - If the message attempting to be edited was not created by the currently logged in account, or
if the passed-in embed is null
or not sendable@CheckReturnValue RestAction<Message> editMessageFormat(java.lang.String format, java.lang.Object... args)
MessageEmbed.
MessageBuilder.appendFormat(String, Object...).
The following ErrorResponses are possible:
MISSING_ACCESS
Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_WRITE in
the TextChannel.UNKNOWN_MESSAGE
format - Format String used to generate the Message's content via
MessageBuilder.appendFormat(String, Object...) specificationargs - The arguments to use in order to be converted in the format stringRestAction - Type: Message
Message with the updated contentjava.lang.IllegalArgumentException - If the provided format String is null or blank, or if
the created message exceeds the 2000 character limitjava.lang.IllegalStateException - If the message attempting to be edited was not created by the currently logged in account@CheckReturnValue RestAction<Message> editMessage(Message newContent)
Message.
The following ErrorResponses are possible:
MISSING_ACCESS
Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_WRITE in
the TextChannel.UNKNOWN_MESSAGE
newContent - the new content of the MessageRestAction - Type: Message
Message with the updated contentjava.lang.IllegalStateException - sendable@CheckReturnValue AuditableRestAction<java.lang.Void> delete()
TextChannel and the current account has
Permission.MESSAGE_MANAGE in the channel.
The following ErrorResponses are possible:
MISSING_ACCESS
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_MANAGE in
the TextChannel when deleting another Member's message
or lost Permission.MESSAGE_MANAGE.UNKNOWN_MESSAGE
The pin was attempted after the Message had been deleted.AuditableRestActionInsufficientPermissionException - If this Message was not sent by the currently logged in account, the Message was sent in a
TextChannel, and the currently logged in account
does not have Permission.MESSAGE_MANAGE in
the channel.java.lang.IllegalStateException - If this Message was not sent by the currently logged in account and it was not sent in a
TextChannel.JDA getJDA()
JDA instance related to this Message.boolean isPinned()
@CheckReturnValue RestAction<java.lang.Void> pin()
MessageChannel's pinned message list.
MessageChannel.pinMessageById(String).
The success or failure of this action will not affect the return of isPinned().
The following ErrorResponses are possible:
MISSING_ACCESS
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_MANAGE in
the TextChannel.UNKNOWN_MESSAGE
The pin request was attempted after the Message had been deleted.RestAction - Type: VoidInsufficientPermissionException - If this Message is from a TextChannel and:
Permission.MESSAGE_READ.
Permission.MESSAGE_MANAGE.
@CheckReturnValue RestAction<java.lang.Void> unpin()
MessageChannel's pinned message list.
MessageChannel.unpinMessageById(String).
The success or failure of this action will not affect the return of isPinned().
The following ErrorResponses are possible:
MISSING_ACCESS
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_MANAGE in
the TextChannel.UNKNOWN_MESSAGE
The unpin request was attempted after the Message had been deleted.RestAction - Type: VoidInsufficientPermissionException - If this Message is from a TextChannel and:
Permission.MESSAGE_READ.
Permission.MESSAGE_MANAGE.
@CheckReturnValue RestAction<java.lang.Void> addReaction(Emote emote)
Emote.
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with 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
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.
Permission.MESSAGE_HISTORYMISSING_PERMISSIONS
Permission.MESSAGE_ADD_REACTION
in the TextChannel when adding the reaction.UNKNOWN_MESSAGE
The reaction request was attempted after the Message had been deleted.emote - The Emote to add as a reaction to this Message.RestAction - Type: VoidInsufficientPermissionException - If the MessageChannel this message was sent in was a TextChannel
and the logged in account does not have
java.lang.IllegalArgumentException - Emote is null.Emote is fake Emote.isFake().Emote cannot be used in the current channel.
See Emote.canInteract(User, MessageChannel) or Emote.canInteract(Member) for more information.@CheckReturnValue RestAction<java.lang.Void> addReaction(java.lang.String unicode)
Reactions are the small emoji/emotes below a message that have a counter beside them showing how many users have reacted with same emoji/emote.
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
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.
Permission.MESSAGE_HISTORYMISSING_PERMISSIONS
Permission.MESSAGE_ADD_REACTION
in the TextChannel when adding the reaction.UNKNOWN_MESSAGE
The reaction request was attempted after the Message had been deleted.unicode - The UTF8 emoji to add as a reaction to this Message.RestAction - Type: VoidInsufficientPermissionException - If the MessageChannel this message was sent in was a TextChannel
and the logged in account does not have
Permission.MESSAGE_ADD_REACTION in the channel.java.lang.IllegalArgumentException - If the provided unicode emoji is null or empty.@CheckReturnValue RestAction<java.lang.Void> clearReactions()
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
TextChannel
due to Permission.MESSAGE_READ being revoked, or the
account lost access to the Guild or Group
typically due to being kicked or removed.MISSING_PERMISSIONS
Permission.MESSAGE_MANAGE
in the TextChannel when adding the reaction.UNKNOWN_MESSAGE
The clear-reactions request was attempted after the Message had been deleted.RestAction - Type: VoidInsufficientPermissionException - If the MessageChannel this message was sent in was a TextChannel
and the currently logged in account does not have
Permission.MESSAGE_MANAGE in the channel.java.lang.IllegalStateException - If this message was not sent in a
TextChannel.MessageType getType()
MessageType of this Message.
Messages can represent more than just simple text sent by Users, they can also be special messages that inform about events occurs. A few examples are the system message informing that a message has been pinned. Another would be the system message informing that a call has been started or ended in a group.
MessageType of this message.