Skip to main content
Represents a text message received from Discord. This represents messages received from MessageChannels.

Overview

The Message interface provides access to all message data including content, attachments, embeds, and reactions. Messages are immutable - JDA does not track changes to messages.

Key Properties

Message Content

getContentRaw()
String
The raw textual content of this message. Does not resolve mentions.Requires MESSAGE_CONTENT intent.
String content = message.getContentRaw();
getContentDisplay()
String
The textual content with mentions resolved to be visually like the Discord client.Requires MESSAGE_CONTENT intent.
String displayContent = message.getContentDisplay();
getContentStripped()
String
Gets the textual content and strips markdown formatting characters.Requires MESSAGE_CONTENT intent.
String strippedContent = message.getContentStripped();

Author Information

getAuthor()
User
The author of this Message.
User author = message.getAuthor();
System.out.println("From: " + author.getAsTag());
getMember()
Member
Returns the author of this Message as a Member.Returns null if the message was not sent in a guild, or if sent by a webhook.
Member member = message.getMember();
if (member != null) {
    System.out.println("Roles: " + member.getRoles());
}
isWebhookMessage()
boolean
Indicates if this Message was sent by a Webhook or an app, instead of a User.
if (message.isWebhookMessage()) {
    return; // Ignore webhook messages
}

Channel and Guild

getChannel()
MessageChannelUnion
Returns the MessageChannel that this message was sent in.
MessageChannel channel = message.getChannel();
channel.sendMessage("Reply").queue();
getGuildChannel()
GuildMessageChannelUnion
Returns the GuildMessageChannel that this message was sent in if it was sent in a Guild.
if (message.isFromGuild()) {
    GuildMessageChannel guildChannel = message.getGuildChannel();
}
getGuild()
Guild
Returns the Guild that this message was sent in.
if (message.isFromGuild()) {
    Guild guild = message.getGuild();
}
isFromGuild()
boolean
Whether this message was sent in a Guild.
if (message.isFromGuild()) {
    // Handle guild message
}
getChannelType()
ChannelType
Gets the ChannelType that this message was received from.
ChannelType type = message.getChannelType();
if (type == ChannelType.PRIVATE) {
    System.out.println("DM message");
}

Attachments and Embeds

getAttachments()
List<Attachment>
An immutable list of Attachments that are attached to this message.Requires MESSAGE_CONTENT intent.
List<Message.Attachment> attachments = message.getAttachments();
for (Message.Attachment attachment : attachments) {
    System.out.println("File: " + attachment.getFileName());
    System.out.println("URL: " + attachment.getUrl());
}
getEmbeds()
List<MessageEmbed>
An immutable list of MessageEmbeds that are part of this Message.Requires MESSAGE_CONTENT intent.
List<MessageEmbed> embeds = message.getEmbeds();
for (MessageEmbed embed : embeds) {
    System.out.println("Title: " + embed.getTitle());
}

Components and Interactions

getComponents()
List<MessageTopLevelComponentUnion>
Layouts of interactive components, usually ActionRows.Requires MESSAGE_CONTENT intent.
List<MessageTopLevelComponentUnion> components = message.getComponents();
getButtons()
List<Button>
All buttons attached to this message.
List<Button> buttons = message.getButtons();

Reactions

getReactions()
List<MessageReaction>
All MessageReactions that are on this Message.
List<MessageReaction> reactions = message.getReactions();
for (MessageReaction reaction : reactions) {
    System.out.println(reaction.getEmoji().getName() + ": " + reaction.getCount());
}

Metadata

getTimeCreated()
OffsetDateTime
The time this message was created.
OffsetDateTime created = message.getTimeCreated();
isEdited()
boolean
Returns whether or not this Message has been edited before.
if (message.isEdited()) {
    OffsetDateTime edited = message.getTimeEdited();
}
getTimeEdited()
OffsetDateTime
Provides the OffsetDateTime defining when this Message was last edited.Returns null if the message has never been edited.
OffsetDateTime editedTime = message.getTimeEdited();
getJumpUrl()
String
Returns the jump-to URL for this message. Clicking this URL in Discord will jump to the message.
String jumpUrl = message.getJumpUrl();
isPinned()
boolean
Whether this message is pinned in its channel.
if (message.isPinned()) {
    System.out.println("This is a pinned message");
}

References

getMessageReference()
MessageReference
Returns the MessageReference for this Message.Returns null if this message has no reference.
MessageReference reference = message.getMessageReference();
if (reference != null) {
    Message referenced = reference.getMessage();
}
getReferencedMessage()
Message
The referenced message for replies.Returns null if not a reply or if the referenced message wasn’t loaded.
Message replyTo = message.getReferencedMessage();
if (replyTo != null) {
    System.out.println("Replying to: " + replyTo.getContentDisplay());
}

Mentions

getMentions()
Mentions
The Mentions used in this message.Includes Members, GuildChannels, Roles, and CustomEmojis.
List<User> mentionedUsers = message.getMentions().getUsers();
List<Role> mentionedRoles = message.getMentions().getRoles();
boolean mentionsEveryone = message.getMentions().mentionsEveryone();

Message Actions

Editing

editMessage(CharSequence newContent)
MessageEditAction
Edits this message and updates the content.
message.editMessage("Updated content")
    .queue();
editMessage(MessageEditData data)
MessageEditAction
Edits this message using the provided MessageEditData.
MessageEditData edit = new MessageEditBuilder()
    .setContent("New content")
    .setEmbeds(embed)
    .build();

message.editMessage(edit).queue();
editMessageEmbeds(Collection<MessageEmbed> embeds)
MessageEditAction
Edits this message using the provided MessageEmbeds.
message.editMessageEmbeds(newEmbed)
    .queue();
editMessageComponents(Collection<MessageTopLevelComponent> components)
MessageEditAction
Edits this message using the provided components.
message.editMessageComponents(ActionRow.of(button))
    .queue();

Deletion

delete()
AuditableRestAction<Void>
Deletes this message from the channel.
message.delete()
    .reason("Inappropriate content")
    .queue();

Reactions

addReaction(Emoji emoji)
RestAction<Void>
Adds a reaction to this message.
message.addReaction(Emoji.fromUnicode("👍"))
    .queue();
removeReaction(Emoji emoji)
RestAction<Void>
Removes the bot’s reaction from this message.
message.removeReaction(Emoji.fromUnicode("👍"))
    .queue();
clearReactions()
RestAction<Void>
Removes all reactions from this message.
message.clearReactions()
    .queue();

Pinning

pin()
RestAction<Void>
Pins this message in its channel.
message.pin()
    .queue();
unpin()
RestAction<Void>
Unpins this message from its channel.
message.unpin()
    .queue();

Replies

reply(CharSequence content)
MessageCreateAction
Replies to this message with the provided content.
message.reply("Got it!")
    .queue();
reply(MessageCreateData data)
MessageCreateAction
Replies to this message with the provided MessageCreateData.
message.reply(MessageCreateData.fromContent("Reply"))
    .setEphemeral(true)
    .queue();

Constants

MAX_CONTENT_LENGTH
int
The maximum amount of characters sendable in one message: 2000
MAX_FILE_SIZE
int
The maximum sendable file size: 10485760 (10 MiB)
MAX_FILE_AMOUNT
int
The maximum amount of files sendable within a single message: 10
MAX_EMBED_COUNT
int
The maximum amount of Embeds that can be added to one message: 10
MAX_REACTIONS
int
The maximum amount of reactions that can be added to one message: 20

Usage Example

// Get message information
Message message = event.getMessage();
System.out.println("Content: " + message.getContentDisplay());
System.out.println("Author: " + message.getAuthor().getAsTag());

// Check attachments
if (!message.getAttachments().isEmpty()) {
    for (Message.Attachment attachment : message.getAttachments()) {
        System.out.println("File: " + attachment.getFileName());
    }
}

// Reply to message
message.reply("Received your message!")
    .queue();

// Add reaction
message.addReaction(Emoji.fromUnicode("✅"))
    .queue();

// Edit message (if bot's own message)
if (message.getAuthor().equals(jda.getSelfUser())) {
    message.editMessage("Updated content")
        .queue();
}

// Delete message
message.delete()
    .reason("Cleanup")
    .queueAfter(5, TimeUnit.SECONDS);

// Check mentions
List<User> mentioned = message.getMentions().getUsers();
for (User user : mentioned) {
    System.out.println("Mentioned: " + user.getAsTag());
}

See Also

Build docs developers (and LLMs) love