Node
Table of Contentsโ
Class Definitionโ
export class Node {}
Propertiesโ
Property Type Description infoLavalinkInfo| nullLavalink node information. nulluntil connected.isNodeLinkboolean Whether 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 | null The current session ID. nulluntil connected.socketWebSocket | null The 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(): stringReturns the full address of this node in
host:portformat.Returnsโ
Type Description string The 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(): booleanReturns whether the node currently has an open WebSocket connection.
Returnsโ
Type Description boolean trueif the WebSocket is open.
deleteSponsorBlock()โ
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()โ
This method is protected and should not be called directly.
protected error(error: Error): voidHandles a WebSocket error event, emitting a
nodeErrorevent on the manager.Parametersโ
Parameter Type Description Optional errorError The 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()โ
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
isNodeLinkistrue.Parametersโ
Parameter Type Description Optional trackTrackThe track to fetch lyrics for. skipTrackSourceboolean Whether to skip the track's source URL. Defaults to false.languagestring The preferred language for lyrics (NodeLink only). Returnsโ
Type Description Promise< Lyrics|NodeLinkGetLyrics>The lyrics data.
getSponsorBlock()โ
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()โ
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
sessionIdtonullif no stored value is found.
lyricsSubscribe()โ
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 guildIdstring The guild ID. skipTrackSourceboolean Whether to skip the track's source URL. Defaults to false.Returnsโ
Type Description Promise<unknown> The response from the Lavalink session lyrics endpoint.
lyricsUnsubscribe()โ
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 guildIdstring The guild ID. Returnsโ
Type Description Promise<unknown> The response from the Lavalink session lyrics endpoint.
message()โ
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
opfield.Parametersโ
Parameter Type Description Optional dBuffer | string The raw message data.
open()โ
This method is protected and should not be called directly.
protected open(): voidHandles the WebSocket
openevent. Clears any pending reconnect timeout, emitsnodeConnect, 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
autoplayTriestimes. EmitsqueueEndif no track is found or autoplay is disabled.Parametersโ
Parameter Type Description Optional playerPlayerThe player. trackTrackThe track that ended. payloadTrackEndEventThe track end payload.
setSponsorBlock()โ
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()โ
This method is protected and should not be called directly.
protected socketClosed(player: Player, payload: WebSocketClosedEvent): voidHandles the
WebSocketClosedEventfrom Lavalink, emittingsocketClosedon the manager.Parametersโ
Parameter Type Description Optional playerPlayerThe player. payloadWebSocketClosedEventThe payload.
trackEnd()โ
async trackEnd(player: Player, track: Track, payload: TrackEndEvent): Promise<void>Handles a
TrackEndEventfrom 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()โ
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 emitstrackErroron the manager.Parametersโ
Parameter Type Description Optional playerPlayerThe player. trackTrackThe track. payloadTrackExceptionEventThe payload.
trackStart()โ
This method is protected and should not be called directly.
protected trackStart(player: Player, track: Track, payload: TrackStartEvent): voidHandles a
TrackStartEvent. Updates player state and emitstrackStarton the manager.Parametersโ
Parameter Type Description Optional playerPlayerThe player. trackTrackThe track. payloadTrackStartEventThe payload.
trackStuck()โ
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 emitstrackStuckon the manager.Parametersโ
Parameter Type Description Optional playerPlayerThe player. trackTrackThe track. payloadTrackStuckEventThe payload.
updateSessionId()โ
async updateSessionId(): Promise<void>Persists the current
sessionIdto the configured storage backend. For JSON/Memory storage, writes a per-node flat file. For Redis, updates a hash field keyed byidentifier::clusterId.