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");
    }
}

  • Method Details

    • registerSlashCommand

      boolean registerSlashCommand(String pluginId, SlashCommandHandler handler)
      Register a slash command handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the slash command handler
      Returns:
      true if registered successfully
    • unregisterSlashCommand

      boolean unregisterSlashCommand(String commandName)
      Unregister a slash command by name.
      Parameters:
      commandName - the command name
      Returns:
      true if unregistered successfully
    • getSlashCommand

      SlashCommandHandler getSlashCommand(String commandName)
      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

      boolean registerContextMenu(String pluginId, ContextMenuHandler handler)
      Register a context menu handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the context menu handler
      Returns:
      true if registered successfully
    • unregisterContextMenu

      boolean unregisterContextMenu(String commandName)
      Unregister a context menu by name.
      Parameters:
      commandName - the command name
      Returns:
      true if unregistered successfully
    • getContextMenu

      ContextMenuHandler getContextMenu(String commandName)
      Get a registered context menu handler.
      Parameters:
      commandName - the command name
      Returns:
      the handler or null if not found
    • registerButtonHandler

      boolean registerButtonHandler(String pluginId, ButtonHandler handler)
      Register a button handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the button handler
      Returns:
      true if registered successfully
    • unregisterButtonHandler

      boolean unregisterButtonHandler(String buttonIdPrefix)
      Unregister a button handler by prefix.
      Parameters:
      buttonIdPrefix - the button ID prefix
      Returns:
      true if unregistered successfully
    • getButtonHandler

      ButtonHandler getButtonHandler(String buttonId)
      Get button handler for a button ID.
      Parameters:
      buttonId - the full button ID
      Returns:
      the handler or null if not found
    • registerSelectMenuHandler

      boolean registerSelectMenuHandler(String pluginId, SelectMenuHandler handler)
      Register a select menu handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the select menu handler
      Returns:
      true if registered successfully
    • unregisterSelectMenuHandler

      boolean unregisterSelectMenuHandler(String selectMenuIdPrefix)
      Unregister a select menu handler by prefix.
      Parameters:
      selectMenuIdPrefix - the select menu ID prefix
      Returns:
      true if unregistered successfully
    • getSelectMenuHandler

      SelectMenuHandler getSelectMenuHandler(String selectMenuId)
      Get select menu handler for a menu ID.
      Parameters:
      selectMenuId - the full select menu ID
      Returns:
      the handler or null if not found
    • registerModalHandler

      boolean registerModalHandler(String pluginId, ModalHandler handler)
      Register a modal handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the modal handler
      Returns:
      true if registered successfully
    • unregisterModalHandler

      boolean unregisterModalHandler(String modalIdPrefix)
      Unregister a modal handler by prefix.
      Parameters:
      modalIdPrefix - the modal ID prefix
      Returns:
      true if unregistered successfully
    • getModalHandler

      ModalHandler getModalHandler(String modalId)
      Get modal handler for a modal ID.
      Parameters:
      modalId - the full modal ID
      Returns:
      the handler or null if not found
    • registerAutoCompleteHandler

      boolean registerAutoCompleteHandler(String pluginId, AutoCompleteHandler handler)
      Register an autocomplete handler.
      Parameters:
      pluginId - the plugin identifier
      handler - the autocomplete handler
      Returns:
      true if registered successfully
    • unregisterAutoCompleteHandler

      boolean unregisterAutoCompleteHandler(String commandName, String optionName)
      Unregister an autocomplete handler.
      Parameters:
      commandName - the command name
      optionName - the option name
      Returns:
      true if unregistered successfully
    • getAutoCompleteHandler

      AutoCompleteHandler getAutoCompleteHandler(String commandName, String optionName)
      Get autocomplete handler for a command option.
      Parameters:
      commandName - the command name
      optionName - the option name
      Returns:
      the handler or null if not found
    • unregisterAll

      int unregisterAll(String pluginId)
      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

      CompletableFuture<Void> syncGuildCommands(long guildId)
      Sync commands for a specific guild.
      Parameters:
      guildId - the guild ID
      Returns:
      future that completes when sync is done
    • syncAllCommandsToGuild

      CompletableFuture<Void> syncAllCommandsToGuild(long guildId)
      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

      Get statistics about registered handlers.
      Returns:
      interaction stats