Classes

Node

Class representing a Lavalink node.

Signature

export declare class Node

JSDoc

@classNode

Properties

readonly retryDelay: number;

The delay between reconnect attempts.

@type{number}
retryAmount: number;

The amount of reconnect attempts left.

@type{number}
ws: WebSocket | null;

The WebSocket for the node.

@type{WebSocket | null}
sessionId: string | null;

The session id of the node.

reconnectTimeout: NodeJS.Timeout | null;

The interval for the reconnect.

@type{NodeJS.Timeout | null}
stats: Stats | null;

The public stats of the node.

@type{Stats | null}
info: NodeInfo | null;

The public info of the node.

@type{NodeInfo | null}
heartbeatInterval: NodeJS.Timeout | null;

Interval handle for the heartbeat ping.

@type{NodeJS.Timeout | null}
isAlive: boolean;

Whether the socket responded to the last ping. Set to false when a ping is sent, back to true when a pong arrives. If still false at the next ping, the socket is terminated.

@type{boolean}
idGetter
get id(): string;

The id of the node.

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	console.log(node.id); // node1
}
@type{string}@readonly
addressGetter
get address(): string;

The socket address to connect the node.

Examples

```ts
const node = manager.nodeManager.get("node1");
if (node) {
	console.log(node.id); // node1
	console.log(node.address); // ws://localhost:2333/v4/websocket
}
}
@type{string}@readonly
readyGetter
get ready(): boolean;

Check if the node is ready to receive events.

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	if (node.ready) {
        console.log("The node is ready");
   } else {
       console.log("The node is not ready");
  }
}
@type{boolean}@readonly
get penalties(): number;

The penalties of the node.

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	console.log(node.id); // node1
	console.log(node.address); // ws://localhost:2333/v4/websocket
	console.log(node.penalties); // the penalties of the node
}
@type{number}@readonly

Methods

message?(payload: unknown): Awaitable<void>;

Define a custom event handler for the node.

Parameters

payload
The payload received from the node.

Returns

Examples

class CustomNode extends Node {
  public async message(payload: any): Promise<void> {
   console.log("Received payload:", payload);
 }
}
connect(): void;

Connect the node to the websocket.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.connect();
@throws{NodeError} If the client data is not valid
stopPlayer(guildId: string): Promise<LavalinkPlayer | null>;

Stop the track in player for the guild.

Parameters

guildId
The guild id to stop the player.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	const player = await node.stopPlayer("guildId");
	console.log(player); // the lavalink player
}
updatePlayer(data: Partial<UpdatePlayerInfo>): Promise<LavalinkPlayer | null>;

Update the player data.

Parameters

data
The player data to update.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	const player = await node.updatePlayer({
		guildId: "guildId",
		noReplace: true,
		playerOptions: {
			paused: false,
			track: { encoded: "encoded track" },
		},
	});

	console.log(player); // the lavalink player
}
destroyPlayer(guildId: string): Promise<void>;

Destroy the player.

Parameters

guildId
The guild id to destroy the player.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) await node.destroyPlayer("guildId");
console.log("Player destroyed");
disconnect(disconnect?: NodeDisconnectInfo): void;

Disconnect the node from the websocket.

Parameters

disconnect
The disconnect options for the node.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.disconnect();
console.log("Node disconnected");
destroy(destroy?: NodeDestroyInfo): void;

Destroy the node.

Parameters

destroy
The destroy options for the node.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.destroy();
console.log("Node destroyed");
updateSession(options: SessionResumingOptions): Promise<LavalinkSession | null>;

Update the session for the node

Parameters

options
The session resuming options.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	const session = await node.updateSession({ resuming: true, timeout: 30000 });
	console.log(session); // the lavalink session
}
reconnect(): void;

Reconnect the node.

Returns

Examples

const node = manager.nodeManager.get("node1");
if (node) node.reconnect();
console.log("Node reconnected");
@throws{NodeError} If the node is not connected
toJSON(): NodeJSON;

Convert the node to JSON.

Returns

The JSON representation of the node.

Examples

const node = manager.nodeManager.get("node1");
if (node) {
	const json = node.toJSON();
	console.log(json);
}