Overview
Interaction events are fired when users interact with your bot through slash commands, buttons, select menus, modals, and context menus.Requirements
To receive interaction events, you must:- Remove the Interactions Endpoint URL in your application dashboard at the Discord Developer Portal
- Handle interactions within 3 seconds or acknowledge them with
deferReply()
Command Interactions
SlashCommandInteractionEvent
Fired when a user executes a slash command. Package:net.dv8tion.jda.api.events.interaction.command
getName()- The command namegetOption(String name)- Get an option by namegetOptions()- Get all optionsgetSubcommandName()- Get subcommand name (if used)getSubcommandGroup()- Get subcommand group (if used)reply(String)- Reply to the interactiondeferReply()- Acknowledge the interaction (for slow commands)getHook()- Get the interaction hook for editing replies
Getting Command Options
UserContextInteractionEvent
Fired when a user context menu command is used. Package:net.dv8tion.jda.api.events.interaction.command
getTarget()- The user the command was used ongetTargetMember()- The member object (null in DMs)
MessageContextInteractionEvent
Fired when a message context menu command is used. Package:net.dv8tion.jda.api.events.interaction.command
getTarget()- The message the command was used on
Component Interactions
ButtonInteractionEvent
Fired when a user clicks a button. Package:net.dv8tion.jda.api.events.interaction.component
getComponentId()- The custom ID of the buttongetButton()- The button componentgetMessage()- The message containing the buttonreply()- Send a new replydeferReply()- Defer a replydeferEdit()- Acknowledge without sending a replyeditMessage()- Edit the message containing the button
Creating Buttons
StringSelectInteractionEvent
Fired when a user selects options from a string select menu. Package:net.dv8tion.jda.api.events.interaction.component
getValues()- List of selected valuesgetSelectedOptions()- List ofSelectOptionobjects
Creating Select Menus
EntitySelectInteractionEvent
Fired when a user selects entities (users, roles, channels) from an entity select menu. Package:net.dv8tion.jda.api.events.interaction.component
getMentions()- Get mentions object with selected entitiesgetValues()- List of selected entity IDs
Modal Interactions
ModalInteractionEvent
Fired when a user submits a modal (form). Package:net.dv8tion.jda.api.events.interaction
getModalId()- The custom ID of the modalgetValue(String id)- Get value of a text input by IDgetValues()- Get all text input values
Creating and Sending Modals
Auto-Complete Interactions
CommandAutoCompleteInteractionEvent
Fired when a user types in an autocomplete-enabled option. Package:net.dv8tion.jda.api.events.interaction.command
getFocusedOption()- The option being autocompletedreplyChoices()- Send autocomplete suggestions
Registering Autocomplete Commands
Generic Interaction Events
GenericInteractionCreateEvent
Fires for all interaction types.GenericComponentInteractionCreateEvent
Fires for all component interactions (buttons, select menus).Example: Complete Interaction System
Best Practices
- Always respond within 3 seconds - Use
deferReply()ordeferEdit()for slow operations - Use ephemeral messages - Set
.setEphemeral(true)for private responses - Validate permissions - Check if the user has permission before executing commands
- Handle errors gracefully - Use
.queue(success, failure)to handle errors - Clean up components - Disable or remove buttons/menus after use
- Use specific events - Don’t rely solely on generic events