Star ✨ on GitHub

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

Properties

PropertyTypeDescription
managerManagerReference to the Manager instance.

Methods

registerPlugin

registerPluginmethod

Register Plugin

Registers a new plugin class with the PluginManager. Registered plugins can then be loaded for nodes that support them.

Parameters
pluginClassrequirednew (...args: any[]) => AbstractPlugin
The constructor of the plugin class to register.

Returns & Example

Returnsvoid

// Example of registering a custom plugin
class MyCustomPlugin extends AbstractPlugin {
  // ... implementation
}
manager.pluginManager.registerPlugin(MyCustomPlugin);

loadPluginsForNode

loadPluginsForNodemethod

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
noderequiredNode
The Node instance for which plugins should be loaded.
lavalinkPluginsrequiredINodeInfo['plugins']
An array of plugins reported by the Lavalink server.

Returns & Example

Returnsvoid

// This method is called internally by the Node class.
// You typically won't need to call this directly.

unloadPluginsForNode

unloadPluginsForNodemethod

Unload Plugins for Node

Unloads all plugins currently loaded for a specific node. This method is called internally by the Node.

Parameters
noderequiredNode
The Node instance from which plugins should be unloaded.

Returns & Example

Returnsvoid

// This method is called internally by the Node class.
// You typically won't need to call this directly.

updateNodePlugins

updateNodePluginsmethod

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
noderequiredNode
The Node instance to update plugins for.

Returns & Example

Returnsvoid

// 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.