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
The main Manager instance that owns this node.
Connection Info
The unique identifier for this node (e.g., "Node-01").
The hostname or IP address.
The port number.
Returns the full address formatted as host:port.
Current WebSocket latency in ms. -1 if disconnected.
State
Whether the WebSocket connection is currently open.
Real-time statistics (CPU, RAM, Uptime).
The current Lavalink session ID.
Supported features (e.g., source:spotify).
Methods
connect()
Initiates the WebSocket connection to the Lavalink server.
Note: NodeManager handles this automatically, but you can call it manually if needed.
await node.connect();
reconnect()
reconnect()#
→voidForces a reconnection attempt using the configured backoff strategy.
node.reconnect();
destroy()
Closes the WebSocket connection and marks the node as destroyed. This will not automatically move players; use NodeManager.eject() for that.
await node.destroy();
ping()
Sends a ping frame to the WebSocket and returns the round-trip time in milliseconds.
const ping = await node.ping();
console.log(`Node latency: ${ping}ms`);
getPenalties()
getPenalties()#
→numberCalculates the current load penalty score for this node. Used by the load balancer to select the best node. Higher score = higher load.
const load = node.getPenalties();
handleAutoPlay(player, previousTrack)
handleAutoPlay(player, previousTrack)#
→Promise<boolean>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.
The player requesting autoplay.
The track that just finished playing.
const success = await node.handleAutoPlay(player, lastTrack);
if (success) console.log("Autoplay started!");