Overview
Message events are fired when messages are created, updated, deleted, or when users interact with them through reactions or polls.Required Intents
Message events require the following Gateway Intents:GUILD_MESSAGES- For messages in guild channelsDIRECT_MESSAGES- For messages in DMsMESSAGE_CONTENT- For accessing message content (privileged)
Message Lifecycle Events
MessageReceivedEvent
Fired when a message is sent in a channel your bot has access to. Package:net.dv8tion.jda.api.events.message
getMessage()- The message that was receivedgetAuthor()- The user who sent the messagegetMember()- The member who sent the message (null in DMs)getChannel()- The channel where the message was sentisWebhookMessage()- Whether the message was sent by a webhook
MessageUpdateEvent
Fired when a message is edited. Package:net.dv8tion.jda.api.events.message
getMessage()- The updated messagegetMessageId()/getMessageIdLong()- The message IDgetChannel()- The channel containing the message
MessageDeleteEvent
Fired when a message is deleted. Package:net.dv8tion.jda.api.events.message
getMessageId()/getMessageIdLong()- The deleted message IDgetChannel()- The channel where the message was deleted
MessageBulkDeleteEvent
Fired when multiple messages are deleted at once (bulk delete). Package:net.dv8tion.jda.api.events.message
getMessageIds()- List of deleted message IDsgetChannel()- The channel where messages were deleted
Reaction Events
Reaction events fire when users add or remove reactions from messages.MessageReactionAddEvent
Fired when a user adds a reaction to a message. Package:net.dv8tion.jda.api.events.message.react
getUser()- The user who added the reactiongetUserIdLong()- The user IDgetReaction()- The reaction that was addedgetEmoji()- The emoji of the reactionretrieveMessage()- Retrieves the full message (RestAction)
MessageReactionRemoveEvent
Fired when a user removes a reaction from a message. Package:net.dv8tion.jda.api.events.message.react
MessageReactionRemoveAllEvent
Fired when all reactions are removed from a message. Package:net.dv8tion.jda.api.events.message.react
MessageReactionRemoveEmojiEvent
Fired when all reactions of a specific emoji are removed from a message. Package:net.dv8tion.jda.api.events.message.react
Poll Events
Poll events fire when users vote on message polls.MessagePollVoteAddEvent
Fired when a user votes in a poll. Package:net.dv8tion.jda.api.events.message.poll
getAnswerId()- The ID of the poll answergetUser()- The user who votedgetMessageIdLong()- The message containing the pollretrieveMessage()- Retrieves the full message
MessagePollVoteRemoveEvent
Fired when a user removes their vote from a poll. Package:net.dv8tion.jda.api.events.message.poll
Generic Message Events
GenericMessageEvent
Base event for all message-related events.GenericMessageReactionEvent
Base event for all reaction-related events.GenericMessagePollVoteEvent
Base event for all poll vote events.Example: Command Handler
Here’s a complete example of a simple command handler using message events:Tips and Best Practices
-
Cache Messages - Message objects are not cached by default. Use
enableCache(CacheFlag.MESSAGE)if you need to access messages later -
Check Permissions - Always verify your bot has permission to send messages before responding:
-
Handle Rate Limits - Use
.queue()instead of.complete()to avoid blocking and handle rate limits gracefully -
Filter Webhooks - Use
isWebhookMessage()to filter out webhook messages if needed -
DM vs Guild - Check if
getMember()is null to determine if a message is from a DM