Skip to main content
Version: v2.10.2 (current)

Node

Table of Contentsโ€‹

Class Definitionโ€‹

export class Node {}

Propertiesโ€‹

Property Type Description
infoLavalinkInfo | nullLavalink node information. null until connected.
isNodeLinkbooleanWhether the node is a NodeLink node.
managerManagerThe manager instance this node belongs to.
optionsNodeOptionsThe resolved options for this node.
restRestThe REST instance for this node.
sessionIdstring | nullThe current session ID. null until connected.
socketWebSocket | nullThe active WebSocket connection, or null.
statsNodeStatsThe current node statistics.

Constructorโ€‹

new Node(manager: Manager, options: NodeOptions)
Parameter Type Description Optional
managerManagerThe manager instance.
optionsNodeOptionsThe node options.

Methodsโ€‹

addressโ€‹

get address(): string

Returns the full address of this node in host:port format.

Returnsโ€‹

Type Description
stringThe node address.

connect()โ€‹

async connect(): Promise<void>

Connects to the Lavalink node via WebSocket. Loads the stored session ID before connecting and includes it in the handshake headers if available.


connectedโ€‹

get connected(): boolean

Returns whether the node currently has an open WebSocket connection.

Returnsโ€‹

Type Description
booleantrue if the WebSocket is open.

deleteSponsorBlock()โ€‹

warning

This method requires the SponsorBlock plugin to be installed on the Lavalink node.

async deleteSponsorBlock(player: Player): Promise<void>

Removes all SponsorBlock segment categories for a player.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.

destroy()โ€‹

async destroy(): Promise<void>

Destroys the node, moves all connected players to another node, closes the WebSocket connection, and removes the node from the manager.


error()โ€‹

warning

This method is protected and should not be called directly.

protected error(error: Error): void

Handles a WebSocket error event, emitting a nodeError event on the manager.

Parametersโ€‹

Parameter Type Description Optional
errorErrorThe error.

fetchInfo()โ€‹

async fetchInfo(): Promise<LavalinkInfo>

Fetches current information from the Lavalink node via the REST API.

Returnsโ€‹

Type Description
Promise<LavalinkInfo>The node info.

getLyrics()โ€‹

warning

This method requires the LavaLyrics plugin, plus either lavasrc-plugin or java-lyrics-plugin.
For NodeLink nodes, no additional plugins are required.

async getLyrics(track: Track, skipTrackSource?: boolean, language?: string): Promise<Lyrics | NodeLinkGetLyrics>

Fetches lyrics for a track. Uses a NodeLink-specific endpoint when isNodeLink is true.

Parametersโ€‹

Parameter Type Description Optional
trackTrackThe track to fetch lyrics for.
skipTrackSourcebooleanWhether to skip the track's source URL. Defaults to false.
languagestringThe preferred language for lyrics (NodeLink only).

Returnsโ€‹

Type Description
Promise<Lyrics | NodeLinkGetLyrics>The lyrics data.

getSponsorBlock()โ€‹

warning

This method requires the SponsorBlock plugin to be installed on the Lavalink node.

async getSponsorBlock(player: Player): Promise<SponsorBlockSegment[]>

Returns the active SponsorBlock segment categories for a player.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.

Returnsโ€‹

Type Description
Promise<SponsorBlockSegment[]>The active segment categories.

handleEvent()โ€‹

warning

This method is protected and should not be called directly.

async handleEvent(payload: PlayerEvent & PlayerEvents): Promise<void>

Routes an incoming Lavalink event payload to the appropriate handler method.

Parametersโ€‹

Parameter Type Description Optional
payloadPlayerEvent & PlayerEventsThe event payload.

loadSessionIds()โ€‹

async loadSessionIds(): Promise<void>

Loads the persisted session ID for this node from the configured storage backend (JSON file or Redis hash). Sets sessionId to null if no stored value is found.


lyricsSubscribe()โ€‹

warning

This method requires the LavaLyrics plugin, plus either lavasrc-plugin or java-lyrics-plugin.
Not supported on NodeLink nodes.

async lyricsSubscribe(guildId: string, skipTrackSource?: boolean): Promise<unknown>

Subscribes a player to real-time lyrics events.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.
skipTrackSourcebooleanWhether to skip the track's source URL. Defaults to false.

Returnsโ€‹

Type Description
Promise<unknown>The response from the Lavalink session lyrics endpoint.

lyricsUnsubscribe()โ€‹

warning

This method requires the java-lyrics-plugin to be installed on the Lavalink node.
Not supported on NodeLink nodes.

async lyricsUnsubscribe(guildId: string): Promise<unknown>

Unsubscribes a player from real-time lyrics events.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
Promise<unknown>The response from the Lavalink session lyrics endpoint.

message()โ€‹

warning

This method is protected and should not be called directly.

async message(d: Buffer | string): Promise<void>

Handles an incoming WebSocket message from Lavalink, routing it based on the op field.

Parametersโ€‹

Parameter Type Description Optional
dBuffer | stringThe raw message data.

open()โ€‹

warning

This method is protected and should not be called directly.

protected open(): void

Handles the WebSocket open event. Clears any pending reconnect timeout, emits nodeConnect, and moves any players currently on a backup node back to this node.


queueEnd()โ€‹

async queueEnd(player: Player, track: Track, payload: TrackEndEvent): Promise<void>

Handles the end of a queue. If autoplay is enabled, attempts to find and play a recommended track up to autoplayTries times. Emits queueEnd if no track is found or autoplay is disabled.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
trackTrackThe track that ended.
payloadTrackEndEventThe track end payload.

setSponsorBlock()โ€‹

warning

This method requires the SponsorBlock plugin to be installed on the Lavalink node.

async setSponsorBlock(player: Player, segments?: SponsorBlockSegment[]): Promise<void>

Sets the active SponsorBlock segment categories for a player. Defaults to [Sponsor, SelfPromo] if no segments are provided.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
segmentsSponsorBlockSegment[]The segment categories to activate. Defaults to [Sponsor, SelfPromo].

socketClosed()โ€‹

warning

This method is protected and should not be called directly.

protected socketClosed(player: Player, payload: WebSocketClosedEvent): void

Handles the WebSocketClosedEvent from Lavalink, emitting socketClosed on the manager.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
payloadWebSocketClosedEventThe payload.

trackEnd()โ€‹

async trackEnd(player: Player, track: Track, payload: TrackEndEvent): Promise<void>

Handles a TrackEndEvent from Lavalink. Manages repeat logic, queue advancement, autoplay, and queue-end behaviour based on the end reason.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
trackTrackThe track that ended.
payloadTrackEndEventThe track end payload.

trackError()โ€‹

warning

This method is protected and should not be called directly.

protected async trackError(player: Player, track: Track, payload: TrackExceptionEvent): Promise<void>

Handles a TrackExceptionEvent. Stops the player and emits trackError on the manager.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
trackTrackThe track.
payloadTrackExceptionEventThe payload.

trackStart()โ€‹

warning

This method is protected and should not be called directly.

protected trackStart(player: Player, track: Track, payload: TrackStartEvent): void

Handles a TrackStartEvent. Updates player state and emits trackStart on the manager.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
trackTrackThe track.
payloadTrackStartEventThe payload.

trackStuck()โ€‹

warning

This method is protected and should not be called directly.

protected async trackStuck(player: Player, track: Track, payload: TrackStuckEvent): Promise<void>

Handles a TrackStuckEvent. Stops the player and emits trackStuck on the manager.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player.
trackTrackThe track.
payloadTrackStuckEventThe payload.

updateSessionId()โ€‹

async updateSessionId(): Promise<void>

Persists the current sessionId to the configured storage backend. For JSON/Memory storage, writes a per-node flat file. For Redis, updates a hash field keyed by identifier::clusterId.