Interface PluginContext
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 Summary
Modifier and TypeMethodDescriptionGets the agent tool registry for registering AI agent tools.net.dv8tion.jda.api.entities.UserGets the bot's JDA user.getCommand(String commandName) Gets a registered text command handler by name.Gets the database manager for plugin data persistence.Gets the event manager for registering event listeners.net.dv8tion.jda.api.entities.GuildgetGuild(long guildId) Gets a guild by ID.getInfo()Gets the plugin informationGets the interaction manager for handling Discord interactions.net.dv8tion.jda.api.JDAgetJDA()Gets the JDA instance.getPudel()Gets the core properties for defining core versionGets the voice manager for handling voice connections and audio.voidLogs a message.voidLogs a message with an exception.voidregisterCommand(String commandName, TextCommandHandler handler) Registers a text command handler programmatically.<T extends net.dv8tion.jda.api.events.GenericEvent>
voidregisterEventListener(PluginEventListener<T> listener) Registers a typed event listener programmatically.voidregisterListener(Listener listener) Registers a listener object with annotated@EventHandlermethods.voidunregisterCommand(String commandName) Unregisters a text command handler.<T extends net.dv8tion.jda.api.events.GenericEvent>
voidunregisterEventListener(PluginEventListener<T> listener) Unregisters a typed event listener.voidunregisterListener(Listener listener) Unregisters a listener object and all its event handlers.
-
Method Details
-
getInfo
-
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
Registers a text command handler programmatically.Preferred: Use the
@TextCommandannotation on a method in your@Pluginclass instead of calling this method directly.- Parameters:
commandName- the command namehandler- the command handler
-
unregisterCommand
Unregisters a text command handler.Not needed when using the
@TextCommandannotation, as annotated commands are automatically unregistered on plugin disable.- Parameters:
commandName- the command name
-
getCommand
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
Registers a listener object with annotated@EventHandlermethods.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
@EventHandlerannotation on methods in aListenerclass instead.Convenience method for
getEventManager().registerEventListener().- Type Parameters:
T- the event type- Parameters:
listener- the event listener
-
unregisterListener
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
-
log
-