PluginManager
API reference for the PluginManager class in Moonlink.js
PluginManager Class
The PluginManager class is responsible for managing and loading plugins that extend Moonlink.js's functionality, primarily by integrating with Lavalink server-side plugins. It handles the registration, loading, and unloading of AbstractPlugin instances.
manager.pluginManager
The PluginManager is accessed through the pluginManager property of the Manager instance. You don't need to create it manually.
Properties
| Property | Type | Description |
|---|---|---|
manager | Manager | Reference to the Manager instance. |
Methods
registerPlugin
Register Plugin
Registers a new plugin class with the PluginManager. Registered plugins can then be loaded for nodes that support them.
Parameters
Returns & Example
Returns
• void
// Example of registering a custom plugin
class MyCustomPlugin extends AbstractPlugin {
// ... implementation
}
manager.pluginManager.registerPlugin(MyCustomPlugin);
loadPluginsForNode
Load Plugins for Node
Loads registered plugins for a specific node based on the Lavalink server's reported plugins. This method is called internally by the Node.
Parameters
Node instance for which plugins should be loaded. Returns & Example
Returns
• void
// This method is called internally by the Node class.
// You typically won't need to call this directly.
unloadPluginsForNode
Unload Plugins for Node
Unloads all plugins currently loaded for a specific node. This method is called internally by the Node.
Parameters
Node instance from which plugins should be unloaded. Returns & Example
Returns
• void
// This method is called internally by the Node class.
// You typically won't need to call this directly.
updateNodePlugins
Update Node Plugins
Updates the plugins loaded for a node based on its latest reported information. This method handles loading new plugins, unloading removed ones, and updating existing ones.
Parameters
Node instance to update plugins for. Returns & Example
Returns
• void
// This method is called internally by the Node class when its info updates.
// You typically won't need to call this directly.
Usage Example
Basic Plugin Registration
Example of how to register a custom plugin with the PluginManager.
import { AbstractPlugin } from 'moonlink.js'; // Assuming AbstractPlugin is exported
class MyCustomPlugin extends AbstractPlugin {
public name = 'MyCustomPlugin';
public capabilities = ['my-custom-capability'];
load(node) {
console.log(`MyCustomPlugin loaded for node ${node.identifier}`);
// Add custom logic here
}
unload(node) {
console.log(`MyCustomPlugin unloaded from node ${node.identifier}`);
// Clean up logic here
}
}
// In your main bot file, after manager initialization:
manager.pluginManager.registerPlugin(MyCustomPlugin);
// Now, if a Lavalink node reports 'my-custom-capability', this plugin will be loaded.