Interface InteractionManager
public interface InteractionManager
Manager for Discord interactions (slash commands, buttons, modals, etc.).
Plugins use this manager to register and manage their interaction handlers.
Example usage in a plugin:
@Plugin(name = "MyPlugin", version = "1.0.0", author = "Author")
public class MyPlugin {
@OnEnable
public void onEnable(PluginContext context) {
InteractionManager manager = context.getInteractionManager();
// Register slash commands
manager.registerSlashCommand("my-plugin", new PingCommand());
manager.registerSlashCommand("my-plugin", new WeatherCommand());
// Register button handlers
manager.registerButtonHandler("my-plugin", new ConfirmButtonHandler());
// Register modal handlers
manager.registerModalHandler("my-plugin", new FeedbackModalHandler());
// Sync commands to Discord (call once after registering all commands)
manager.syncCommands();
}
@OnDisable
public void onDisable(PluginContext context) {
// Unregister all handlers for this plugin
context.getInteractionManager().unregisterAll("my-plugin");
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordStatistics about registered interaction handlers. -
Method Summary
Modifier and TypeMethodDescriptionGet all registered slash commands.getAutoCompleteHandler(String commandName, String optionName) Get autocomplete handler for a command option.getButtonHandler(String buttonId) Get button handler for a button ID.getContextMenu(String commandName) Get a registered context menu handler.getModalHandler(String modalId) Get modal handler for a modal ID.getSelectMenuHandler(String selectMenuId) Get select menu handler for a menu ID.getSlashCommand(String commandName) Get a registered slash command handler.getStats()Get statistics about registered handlers.booleanregisterAutoCompleteHandler(String pluginId, AutoCompleteHandler handler) Register an autocomplete handler.booleanregisterButtonHandler(String pluginId, ButtonHandler handler) Register a button handler.booleanregisterContextMenu(String pluginId, ContextMenuHandler handler) Register a context menu handler.booleanregisterModalHandler(String pluginId, ModalHandler handler) Register a modal handler.booleanregisterSelectMenuHandler(String pluginId, SelectMenuHandler handler) Register a select menu handler.booleanregisterSlashCommand(String pluginId, SlashCommandHandler handler) Register a slash command handler.syncAllCommandsToGuild(long guildId) Sync all commands (core + plugin) to a specific guild as guild-level commands.Sync all registered slash commands and context menus to Discord.syncGuildCommands(long guildId) Sync commands for a specific guild.intunregisterAll(String pluginId) Unregister all handlers from a plugin.booleanunregisterAutoCompleteHandler(String commandName, String optionName) Unregister an autocomplete handler.booleanunregisterButtonHandler(String buttonIdPrefix) Unregister a button handler by prefix.booleanunregisterContextMenu(String commandName) Unregister a context menu by name.booleanunregisterModalHandler(String modalIdPrefix) Unregister a modal handler by prefix.booleanunregisterSelectMenuHandler(String selectMenuIdPrefix) Unregister a select menu handler by prefix.booleanunregisterSlashCommand(String commandName) Unregister a slash command by name.
-
Method Details
-
registerSlashCommand
Register a slash command handler.- Parameters:
pluginId- the plugin identifierhandler- the slash command handler- Returns:
- true if registered successfully
-
unregisterSlashCommand
Unregister a slash command by name.- Parameters:
commandName- the command name- Returns:
- true if unregistered successfully
-
getSlashCommand
Get a registered slash command handler.- Parameters:
commandName- the command name- Returns:
- the handler or null if not found
-
getAllSlashCommands
Collection<SlashCommandHandler> getAllSlashCommands()Get all registered slash commands.- Returns:
- collection of slash command handlers
-
registerContextMenu
Register a context menu handler.- Parameters:
pluginId- the plugin identifierhandler- the context menu handler- Returns:
- true if registered successfully
-
unregisterContextMenu
Unregister a context menu by name.- Parameters:
commandName- the command name- Returns:
- true if unregistered successfully
-
getContextMenu
Get a registered context menu handler.- Parameters:
commandName- the command name- Returns:
- the handler or null if not found
-
registerButtonHandler
Register a button handler.- Parameters:
pluginId- the plugin identifierhandler- the button handler- Returns:
- true if registered successfully
-
unregisterButtonHandler
Unregister a button handler by prefix.- Parameters:
buttonIdPrefix- the button ID prefix- Returns:
- true if unregistered successfully
-
getButtonHandler
Get button handler for a button ID.- Parameters:
buttonId- the full button ID- Returns:
- the handler or null if not found
-
registerSelectMenuHandler
Register a select menu handler.- Parameters:
pluginId- the plugin identifierhandler- the select menu handler- Returns:
- true if registered successfully
-
unregisterSelectMenuHandler
Unregister a select menu handler by prefix.- Parameters:
selectMenuIdPrefix- the select menu ID prefix- Returns:
- true if unregistered successfully
-
getSelectMenuHandler
Get select menu handler for a menu ID.- Parameters:
selectMenuId- the full select menu ID- Returns:
- the handler or null if not found
-
registerModalHandler
Register a modal handler.- Parameters:
pluginId- the plugin identifierhandler- the modal handler- Returns:
- true if registered successfully
-
unregisterModalHandler
Unregister a modal handler by prefix.- Parameters:
modalIdPrefix- the modal ID prefix- Returns:
- true if unregistered successfully
-
getModalHandler
Get modal handler for a modal ID.- Parameters:
modalId- the full modal ID- Returns:
- the handler or null if not found
-
registerAutoCompleteHandler
Register an autocomplete handler.- Parameters:
pluginId- the plugin identifierhandler- the autocomplete handler- Returns:
- true if registered successfully
-
unregisterAutoCompleteHandler
-
getAutoCompleteHandler
Get autocomplete handler for a command option.- Parameters:
commandName- the command nameoptionName- the option name- Returns:
- the handler or null if not found
-
unregisterAll
Unregister all handlers from a plugin.- Parameters:
pluginId- the plugin identifier- Returns:
- number of handlers unregistered
-
syncCommands
CompletableFuture<Void> syncCommands()Sync all registered slash commands and context menus to Discord.Call this after registering all your commands. Global commands may take up to 1 hour to appear. Guild commands are instant.
- Returns:
- future that completes when sync is done
-
syncGuildCommands
Sync commands for a specific guild.- Parameters:
guildId- the guild ID- Returns:
- future that completes when sync is done
-
syncAllCommandsToGuild
Sync all commands (core + plugin) to a specific guild as guild-level commands.This ensures commands are available instantly when the bot joins a new guild, instead of waiting up to 1 hour for global command propagation.
- Parameters:
guildId- the guild ID- Returns:
- future that completes when sync is done
-
getStats
InteractionManager.InteractionStats getStats()Get statistics about registered handlers.- Returns:
- interaction stats
-