Skip to content

Lavalink Manager

The LavalinkManager is the primary entry point for the library. It manages node connections, player lifecycles, and search operations.

Configuration Options

When creating a LavalinkManager instance, you can provide the following options:

OptionTypeDescription
nodesNodeOptions[]Array of Lavalink nodes to connect to.
sendFunctionA function to send voice payloads to Discord.
autoResumebooleanWhether to automatically resume sessions on reconnect.
pluginsPlugin[]Array of plugins to load.

Node Options

OptionTypeDescription
hoststringThe Lavalink server hostname.
portnumberThe Lavalink server port.
passwordstringThe Lavalink server password.
securebooleanUse secure (WSS/HTTPS) connection.
version'v3' | 'v4'The Lavalink version.

Methods

init(userId: string)

Initializes the manager and connects to all configured nodes.

createPlayer(options: PlayerOptions)

Creates a new player for a guild.

  • guildId: Discord guild ID.
  • voiceChannelId: The channel to join.
  • textChannelId: The channel for notifications.
  • autoplay: Enable automatic recommendations.

use(plugin: Plugin)

Injects a plugin into the manager. Can be called at any time.

destroy()

Gracefully shuts down all node connections and destroys all active players.

Events

The manager is an EventEmitter:

typescript
manager.on('trackStart', (player, track) => {
    console.log(`Now playing: ${track.info.title}`);
});

manager.on('nodeConnect', (node) => {
    console.log(`Node ${node.options.host} is online.`);
});

manager.on('nodeError', (node, error) => {
    console.error(`Node ${node.options.host} failed: ${error.message}`);
});

manager.on('playerDestroy', (player) => {
    console.log(`Player destroyed for guild ${player.guildId}`);
});

Released under the MIT License.