Star ✨ on GitHub

Node

Represents a direct connection to a single Lavalink server. It handles the WebSocket connection, session resuming, and payload transmission.

The Node class represents a single Lavalink server instance. It manages the persistent WebSocket connection, handles incoming events (like track starts/ends), and maintains the synchronization state with the server.

Properties

Node Properties

Core state and connection details for this Lavalink node.

References

managerManager

The main Manager instance that owns this node.

Connection Info

identifierstring

The unique identifier for this node (e.g., "Node-01").

hoststring

The hostname or IP address.

portnumber

The port number.

addressstring

Returns the full address formatted as host:port.

latencynumber

Current WebSocket latency in ms. -1 if disconnected.

State

connectedboolean

Whether the WebSocket connection is currently open.

statsINodeStats

Real-time statistics (CPU, RAM, Uptime).

sessionIdstring

The current Lavalink session ID.

capabilitiesSet<string>

Supported features (e.g., source:spotify).

Methods

connect()

connect()#

Initiates the WebSocket connection to the Lavalink server. Note: NodeManager handles this automatically, but you can call it manually if needed.

Example
await node.connect();

reconnect()

Forces a reconnection attempt using the configured backoff strategy.

Example
node.reconnect();

destroy()

destroy()#

Closes the WebSocket connection and marks the node as destroyed. This will not automatically move players; use NodeManager.eject() for that.

Example
await node.destroy();

ping()

ping()#

Sends a ping frame to the WebSocket and returns the round-trip time in milliseconds.

Example
const ping = await node.ping();
console.log(`Node latency: ${ping}ms`);

getPenalties()

Calculates the current load penalty score for this node. Used by the load balancer to select the best node. Higher score = higher load.

Example
const load = node.getPenalties();

handleAutoPlay(player, previousTrack)

Attempts to find and play a similar track based on the previous one. Supports YouTube Mix, Spotify, Deezer, and Apple Music recommendations depending on Node capabilities.

playerPlayer required

The player requesting autoplay.

previousTrackTrack required

The track that just finished playing.

Example
const success = await node.handleAutoPlay(player, lastTrack);
if (success) console.log("Autoplay started!");