java.util.Formattable
, ISnowflake
public interface Message extends ISnowflake, java.util.Formattable
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.
MessageType
enum.MessageBuilder
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
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:
getContentRaw()
(Example: %#s
- uses getContentDisplay()
)%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 | Description |
---|---|---|
static class |
Message.Attachment |
Represents a
Message file attachment. |
static class |
Message.MentionType |
Mention formatting constants, useful for use with
Patterns |
Modifier and Type | Field | Description |
---|---|---|
static java.util.regex.Pattern |
INVITE_PATTERN |
Pattern used to find instant invites in messages.
|
static int |
MAX_CONTENT_LENGTH |
The maximum amount of characters sendable in one message.
|
static int |
MAX_FILE_AMOUNT |
The maximum amount of files sendable within a single message (10)
|
static int |
MAX_FILE_SIZE |
The maximum sendable file size (8 MiB)
|
static int |
MAX_FILE_SIZE_NITRO |
The maximum sendable file size for nitro (50 MiB)
|
Modifier and Type | Method | Description |
---|---|---|
RestAction<java.lang.Void> |
addReaction(java.lang.String unicode) |
Adds a reaction to this Message using a UTF8 emoji.
|
RestAction<java.lang.Void> |
addReaction(Emote emote) |
Adds a reaction to this Message using an
Emote . |
RestAction<java.lang.Void> |
clearReactions() |
Removes all reactions from this Message.
|
AuditableRestAction<java.lang.Void> |
delete() |
Deletes this Message from Discord.
|
MessageAction |
editMessage(java.lang.CharSequence newContent) |
Edits this Message's content to the provided String.
|
MessageAction |
editMessage(Message newContent) |
Edits this Message's content to the provided
Message . |
MessageAction |
editMessage(MessageEmbed newContent) |
Edits this Message's content to the provided
MessageEmbed . |
MessageAction |
editMessageFormat(java.lang.String format,
java.lang.Object... args) |
Edits this Message's content to the provided format.
|
java.util.List<Message.Attachment> |
getAttachments() |
An unmodifiable list of
Attachments that are attached to this message. |
User |
getAuthor() |
The author of this Message
|
Category |
getCategory() |
The
Category this
message was sent in. |
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 |
getContentDisplay() |
The textual content of this message in the format that would be shown to the Discord client.
|
java.lang.String |
getContentRaw() |
The raw textual content of this message.
|
java.lang.String |
getContentStripped() |
Gets the textual content of this message using
getContentDisplay() and then strips it of all markdown characters
like *, **, __, ~~ that provide text formatting. |
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. |
java.util.List<java.lang.String> |
getInvites() |
Creates an immutable List of
Invite codes
that are included in this Message. |
JDA |
getJDA() |
Returns the
JDA instance related to this Message. |
java.lang.String |
getJumpUrl() |
Returns the jump-to URL for the received 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<Member> |
getMentionedMembers() |
Creates an immutable list of
Members
representing the users of getMentionedUsers() in the
Guild this Message was sent in. |
java.util.List<Member> |
getMentionedMembers(Guild guild) |
Creates an immutable list of
Members
representing the users of getMentionedUsers() in the specified
Guild . |
java.util.List<Role> |
getMentionedRoles() |
A immutable list of all mentioned
Roles . |
java.util.List<User> |
getMentionedUsers() |
An immutable list of all mentioned
Users . |
java.util.List<IMentionable> |
getMentions(Message.MentionType... types) |
Combines all instances of
IMentionable
filtered by the specified MentionType values. |
java.lang.String |
getNonce() |
Validation nonce for this Message
This can be used to validate that a Message was properly sent to the Discord Service. |
PrivateChannel |
getPrivateChannel() |
Returns the
PrivateChannel that this message was sent in. |
java.util.List<MessageReaction> |
getReactions() |
All
MessageReactions that are on this Message. |
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(IMentionable mentionable,
Message.MentionType... types) |
Checks if given
IMentionable
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 |
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, getIdLong
static final int MAX_FILE_SIZE
MessageAction.addFile(...)
,
Constant Field Valuesstatic final int MAX_FILE_SIZE_NITRO
MessageAction.addFile(...)
,
Constant Field Valuesstatic final int MAX_FILE_AMOUNT
MessageAction.addFile(...)
,
Constant Field Valuesstatic final int MAX_CONTENT_LENGTH
MessageAction.append(...)
,
Constant Field Valuesstatic final java.util.regex.Pattern INVITE_PATTERN
getInvites()
java.util.List<User> getMentionedUsers()
Users
.
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.util.List<TextChannel> getMentionedChannels()
TextChannels
.
This may include TextChannels from other Guilds
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.util.List<Role> getMentionedRoles()
Roles
.
This may include Roles from other Guilds
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.util.List<Member> getMentionedMembers(Guild guild)
Members
representing the users of getMentionedUsers()
in the specified
Guild
.
guild
- Non-null Guild
that will be used to retrieve Members.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.IllegalArgumentException
- If the specified Guild is null
java.util.List<Member> getMentionedMembers()
Members
representing the users of getMentionedUsers()
in the
Guild
this Message was sent in.
getGuild()
output Guild to getMentionedMembers(Guild)
.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.IllegalStateException
- If this message was not sent in a TextChannel
java.util.List<IMentionable> getMentions(Message.MentionType... types)
IMentionable
filtered by the specified MentionType
values.
getMentionedMembers()
to avoid duplicates.
If no MentionType values are given this will fallback to all types.
types
- Amount of MentionTypes
to include in the list of mentionsIMentionable
instancesjava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.IllegalArgumentException
- If provided with null
boolean isMentioned(IMentionable mentionable, Message.MentionType... types)
IMentionable
was mentioned in this message in any way (@User, @everyone, @here, @Role).
MentionTypes
are
specified this will fallback to all mention types.
MentionType.HERE
and MentionType.EVERYONE
will only be checked, if the given IMentionable
is of type
User
or Member
.
Online status of Users/Members is NOT considered when checking MentionType.HERE
.
mentionable
- The mentionable entity to check on.types
- The types to include when checking whether this type was mentioned.
This will be used with getMentions(MentionType...)
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
boolean mentionsEveryone()
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()
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.String getJumpUrl()
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.String getContentDisplay()
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 getContentRaw()
instead
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.String getContentRaw()
IMentionable
entities like getContentDisplay()
does. This means that this is the completely raw textual content of the message
received from Discord and can contain mentions specified by
Discord's Message Formatting.java.lang.String getContentStripped()
getContentDisplay()
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.getContentDisplay()
with all text formatting characters removed or escaped.java.util.List<java.lang.String> getInvites()
Invite
codes
that are included in this Message.
Pattern
provided
under INVITE_PATTERN
to construct a Matcher
that will
parse the getContentRaw()
output and include all codes it finds in a list.
You can use the codes to retrieve/validate invites via
Invite.resolve(JDA, String)
java.lang.String getNonce()
MessageBuilder.setNonce(String)
!MessageBuilder.setNonce(String)
,
Cryptographic Nonce - Wikipediaboolean 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
.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
ChannelType getChannelType()
ChannelType
that this message was received from.
ChannelType.VOICE
as Messages can't be sent to
VoiceChannels
.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
boolean isWebhookMessage()
Webhook
instead of a
User
.
Webhook
.MessageChannel getChannel()
MessageChannel
that this message was sent in.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
Category getCategory()
Category
this
message was sent in. This will always be null
for DMs and Groups.
getTextChannel().getParent()
.Category
for this messagejava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.util.List<MessageReaction> getReactions()
MessageReactions
that are on this Message.boolean isTTS()
@CheckReturnValue MessageAction editMessage(java.lang.CharSequence newContent)
This message instance will not be updated by this operation, please use the response message instead.
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 MessageMessageAction
Message
with the updated contentjava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.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 MessageAction editMessage(MessageEmbed newContent)
MessageEmbed
.
This message instance will not be updated by this operation, please use the response message instead.
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 MessageMessageAction
Message
with the updated contentjava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.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 MessageAction editMessageFormat(java.lang.String format, java.lang.Object... args)
MessageBuilder.appendFormat(String, Object...)
.
This message instance will not be updated by this operation, please use the response message instead.
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 stringMessageAction
Message
with the updated contentjava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.IllegalArgumentException
- If the provided format String is null
or blank, or if
the created message exceeds the 2000 character limitjava.util.IllegalFormatException
- 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.java.lang.IllegalStateException
- If the message attempting to be edited was not created by the currently logged in account@CheckReturnValue MessageAction editMessage(Message newContent)
Message
.
This message instance will not be updated by this operation, please use the response message instead.
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 MessageMessageAction
Message
with the updated contentjava.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
java.lang.IllegalStateException
- sendable
@CheckReturnValue AuditableRestAction<java.lang.Void> delete()
TextChannel
and the current account has
Permission.MESSAGE_MANAGE
in the channel.
To delete many messages at once in a MessageChannel
you should use MessageChannel.purgeMessages(Collection)
instead.
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.AuditableRestAction
java.lang.UnsupportedOperationException
- If this is a Data Message (output of MessageBuilder
)InsufficientPermissionException
- 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
.TextChannel.deleteMessages(Collection)
,
MessageChannel.purgeMessages(List)
JDA getJDA()
JDA
instance related to this Message.java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
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: Void
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
InsufficientPermissionException
- 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: Void
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
InsufficientPermissionException
- If this Message is from a TextChannel
and:
Permission.MESSAGE_READ
.
Permission.MESSAGE_MANAGE
.
@CheckReturnValue RestAction<java.lang.Void> addReaction(Emote emote)
Emote
.
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 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_HISTORY
MISSING_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: Void
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
InsufficientPermissionException
- 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)
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 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_HISTORY
MISSING_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: Void
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
InsufficientPermissionException
- If the MessageChannel this message was sent in was a TextChannel
and the logged in account does not have
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: Void
java.lang.UnsupportedOperationException
- If this is not a Received Message from MessageType.DEFAULT
InsufficientPermissionException
- 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.