Interface PluginContext


public interface PluginContext
Context provided to plugins for accessing bot services and Discord API.

Plugins should use this context to interact with the bot and access shared services. The preferred approach is to use annotations in your @Plugin class instead of calling these methods directly.

Example:

@Plugin(name = "MyPlugin", version = "1.0.0", author = "Author")
public class MyPlugin {

    @OnEnable
    public void onEnable(PluginContext context) {
        context.log("info", "Plugin enabled on Pudel " + context.getPudel().getVersion());
    }

    @SlashCommand(name = "hello", description = "Say hello")
    public void hello(SlashCommandInteractionEvent event) {
        event.reply("Hello!").queue();
    }

    @TextCommand(name = "ping", description = "Check bot latency")
    public void ping(CommandContext context) {
        context.reply("Pong!");
    }
}

  • Method Details

    • getInfo

      PluginInfo getInfo()
      Gets the plugin information
      Returns:
      PluginInfo
    • getPudel

      PudelProperties getPudel()
      Gets the core properties for defining core version
      Returns:
      the PudelProperties instance
    • getJDA

      net.dv8tion.jda.api.JDA getJDA()
      Gets the JDA instance.
      Returns:
      the JDA instance
    • getBotUser

      net.dv8tion.jda.api.entities.User getBotUser()
      Gets the bot's JDA user.
      Returns:
      the bot user
    • getGuild

      net.dv8tion.jda.api.entities.Guild getGuild(long guildId)
      Gets a guild by ID.
      Parameters:
      guildId - the guild ID
      Returns:
      the guild or null if not found
    • registerCommand

      void registerCommand(String commandName, TextCommandHandler handler)
      Registers a text command handler programmatically.

      Preferred: Use the @TextCommand annotation on a method in your @Plugin class instead of calling this method directly.

      Parameters:
      commandName - the command name
      handler - the command handler
    • unregisterCommand

      void unregisterCommand(String commandName)
      Unregisters a text command handler.

      Not needed when using the @TextCommand annotation, as annotated commands are automatically unregistered on plugin disable.

      Parameters:
      commandName - the command name
    • getCommand

      TextCommandHandler getCommand(String commandName)
      Gets a registered text command handler by name.
      Parameters:
      commandName - the command name
      Returns:
      the handler or null if not found
    • getEventManager

      EventManager getEventManager()
      Gets the event manager for registering event listeners.
      Returns:
      the event manager
    • registerListener

      void registerListener(Listener listener)
      Registers a listener object with annotated @EventHandler methods.

      Convenience method for getEventManager().registerListener().

      Parameters:
      listener - the listener object
    • registerEventListener

      <T extends net.dv8tion.jda.api.events.GenericEvent> void registerEventListener(PluginEventListener<T> listener)
      Registers a typed event listener programmatically.

      Preferred: Use the @EventHandler annotation on methods in a Listener class instead.

      Convenience method for getEventManager().registerEventListener().

      Type Parameters:
      T - the event type
      Parameters:
      listener - the event listener
    • unregisterListener

      void unregisterListener(Listener listener)
      Unregisters a listener object and all its event handlers.
      Parameters:
      listener - the listener to unregister
    • unregisterEventListener

      <T extends net.dv8tion.jda.api.events.GenericEvent> void unregisterEventListener(PluginEventListener<T> listener)
      Unregisters a typed event listener.
      Type Parameters:
      T - the event type
      Parameters:
      listener - the event listener to unregister
    • getVoiceManager

      VoiceManager getVoiceManager()
      Gets the voice manager for handling voice connections and audio.
      Returns:
      the voice manager
    • getAgentToolRegistry

      AgentToolRegistry getAgentToolRegistry()
      Gets the agent tool registry for registering AI agent tools.

      Plugins can register custom tools that the AI agent can use when processing user requests.

      Example:

      context.getAgentToolRegistry().registerProvider("my-plugin", new MyTools());
      
      Returns:
      the agent tool registry
    • getInteractionManager

      InteractionManager getInteractionManager()
      Gets the interaction manager for handling Discord interactions.

      Plugins use this to register slash commands, buttons, modals, select menus, context menus, and autocomplete handlers.

      Example:

      
      InteractionManager manager = context.getInteractionManager();
      
      // Register slash command
      manager.registerSlashCommand("my-plugin", new PingCommand());
      
      // Register button handler
      manager.registerButtonHandler("my-plugin", new MyButtonHandler());
      
      // Sync commands to Discord
      manager.syncCommands();
      
      
      Returns:
      the interaction manager
    • getDatabaseManager

      PluginDatabaseManager getDatabaseManager()
      Gets the database manager for plugin data persistence.

      Each plugin gets its own isolated database namespace with tables prefixed by a unique identifier. Plugins interact through a JPA-like repository pattern - no raw SQL is allowed.

      Example:

      
      PluginDatabaseManager db = context.getDatabaseManager();
      
      // Define schema
      TableSchema schema = TableSchema.builder("settings")
          .column("user_id", ColumnType.BIGINT, false)
          .column("key", ColumnType.STRING, 100, false)
          .column("value", ColumnType.TEXT, true)
          .build();
      
      // Create table (safe to call every startup)
      db.createTable(schema);
      
      // Get repository for CRUD operations
      PluginRepository<Setting> repo = db.getRepository("settings", Setting.class);
      
      // Or use simple key-value store
      db.getKeyValueStore().set("config.enabled", true);
      
      
      Returns:
      the plugin database manager
    • log

      void log(String level, String message)
      Logs a message.
      Parameters:
      level - the log level
      message - the message
    • log

      void log(String level, String message, Throwable throwable)
      Logs a message with an exception.
      Parameters:
      level - the log level
      message - the message
      throwable - the exception