Skip to content

LavalinkNode

Defined in: src/structures/Node.ts:28

Lavalink Node creator class

new LavalinkNode(options: LavalinkNodeOptions, manager: NodeManager): LavalinkNode;

Defined in: src/structures/Node.ts:171

Create a new Node

ParameterTypeDescription
optionsLavalinkNodeOptionsLavalink Node Options
managerNodeManagerNode Manager

LavalinkNode

// don't create a node manually, instead use:
client.lavalink.nodeManager.createNode(options)
Property (defined in)TypeDefault valueDescription
calls
(src/structures/Node.ts:38)
number0The amount of rest calls the node has made.
decode
(src/structures/Node.ts:727)
objectundefinedDecode Track or Tracks
decode.multipleTracks
(src/structures/Node.ts:759)
(encodeds: string[], requester: unknown) => Promise<Track[]>undefinedDecodes multiple tracks into their info Example `const encodedBase64_1 = ‘QAACDgMACk5vIERpZ2dpdHkAC0JsYWNrc3RyZWV0AAAAAAAEo4AABjkxNjQ5NgABAB9odHRwczovL2RlZXplci5jb20vdHJhY2svOTE2NDk2AQBpaHR0cHM6Ly…
decode.singleTrack
(src/structures/Node.ts:740)
(encoded: string, requester: unknown) => Promise<Track>undefinedDecode a single track into its info Example `const encodedBase64 = ‘QAACDgMACk5vIERpZ2dpdHkAC0JsYWNrc3RyZWV0AAAAAAAEo4AABjkxNjQ5NgABAB9odHRwczovL2RlZXplci5jb20vdHJhY2svOTE2NDk2AQBpaHR0cHM6Ly9lLWNk…
info
(src/structures/Node.ts:77)
LavalinkInfonullActual Lavalink Information of the Node
isAlive
(src/structures/Node.ts:34)
booleanfalse
lyrics
(src/structures/Node.ts:771)
objectundefined
lyrics.get
(src/structures/Node.ts:785)
(track: Track, skipTrackSource: boolean) => Promise<LyricsResult>undefinedGet the lyrics of a track Example const lyrics = await player.node.lyrics.get(track, true); // use it of player instead: // const lyrics = await player.getLyrics(track, true);
lyrics.getCurrent
(src/structures/Node.ts:814)
(guildId: string, skipTrackSource: boolean) => Promise<LyricsResult>undefinedGet the lyrics of the current playing track Example const lyrics = await player.node.lyrics.getCurrent(guildId); // use it of player instead: // const lyrics = await player.getCurrentLyrics();
lyrics.subscribe
(src/structures/Node.ts:843)
(guildId: string) => Promise<unknown>undefinedsubscribe to lyrics updates for a guild Example await player.node.lyrics.subscribe(guildId); // use it of player instead: // const lyrics = await player.subscribeLyrics();
lyrics.unsubscribe
(src/structures/Node.ts:866)
(guildId: string) => Promise<void>undefinedunsubscribe from lyrics updates for a guild Example await player.node.lyrics.unsubscribe(guildId); // use it of player instead: // const lyrics = await player.unsubscribeLyrics();
options
(src/structures/Node.ts:36)
LavalinkNodeOptionsundefinedThe provided Options of the Node
reconnectionState
(src/structures/Node.ts:79)
ReconnectionStateReconnectionState.IDLEcurrent state of the Reconnections
resuming
(src/structures/Node.ts:75)
objectundefinedWhether the node resuming is enabled or not
resuming.enabled
(src/structures/Node.ts:75)
booleanundefined
resuming.timeout
(src/structures/Node.ts:75)
numberundefined
routePlannerApi
(src/structures/Node.ts:938)
objectundefinedLavalink’s Route Planner Api
routePlannerApi.getStatus
(src/structures/Node.ts:950)
() => Promise<RoutePlanner>undefinedGet routplanner Info from Lavalink for ip rotation Example `const routePlannerStatus = await player.node.routePlannerApi.getStatus(); const usedBlock = routePlannerStatus.details?.ipBlock; const c…
routePlannerApi.unmarkAllFailedAddresses
(src/structures/Node.ts:984)
() => Promise<unknown>undefinedRelease all blacklisted IP addresses into pool of IPs Example await player.node.routePlannerApi.unmarkAllFailedAddresses();
routePlannerApi.unmarkFailedAddress
(src/structures/Node.ts:965)
(address: string) => Promise<unknown>undefinedRelease blacklisted IP address into pool of IPs for ip rotation Example await player.node.routePlannerApi.unmarkFailedAddress("ipv6address");
sessionId?
(src/structures/Node.ts:73)
stringnullThe current sessionId, only present when connected
stats
(src/structures/Node.ts:40)
NodeStatsundefinedStats from lavalink, will be updated via an interval by lavalink.
get connected(): boolean;

Defined in: src/structures/Node.ts:136

Returns if connected to the Node.

const isConnected = player.node.connected;
console.log("node is connected: ", isConnected ? "yes" : "no")

boolean


get connectionStatus(): string;

Defined in: src/structures/Node.ts:153

Returns the current ConnectionStatus

try {
const statusOfConnection = player.node.connectionStatus;
console.log("node's connection status is:", statusOfConnection)
} catch (error) {
console.error("no socket available?", error)
}

string


get heartBeatPing(): number;

Defined in: src/structures/Node.ts:101

Returns the Heartbeat Ping of the Node

number


get id(): string;

Defined in: src/structures/Node.ts:529

Get the id of the node

const nodeId = player.node.id;
console.log("node id is: ", nodeId)

string


get isNodeReconnecting(): boolean;

Defined in: src/structures/Node.ts:1078

If already trying to reconnect or pending, return

boolean


get reconnectionAttemptCount(): number;

Defined in: src/structures/Node.ts:1114

number

connect(sessionId?: string): void;

Defined in: src/structures/Node.ts:463

Connect to the Lavalink Node

ParameterTypeDescription
sessionId?stringProvide the Session Id of the previous connection, to resume the node and it’s player(s)

void

void

player.node.connect(); // if provided on bootup in managerOptions#nodes, this will be called automatically when doing lavalink.init()
// or connect from a resuming session:
player.node.connect("sessionId");

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

Defined in: src/structures/Node.ts:1658

Delete the sponsorblock plugins

ParameterTypeDescription
playerPlayerpassthrough the player

Promise<void>

void

// use it on the player via player.deleteSponsorBlock();
const sponsorBlockSegments = await player.node.deleteSponsorBlock(player);

destroy(
destroyReason?: string,
deleteNode?: boolean,
movePlayers?: boolean): void;

Defined in: src/structures/Node.ts:550

Destroys the Node-Connection (Websocket) and all player’s of the node

ParameterTypeDefault valueDescription
destroyReason?stringundefinedDestroy Reason to use when destroying the players
deleteNode?booleantruewhether to delete the nodte from the nodes list too, if false it will emit a disconnect.
movePlayers?booleanfalsewhether to movePlayers to different eligible connected node. If false players won’t be moved

void

void

true
false

Destroys node and its players

player.node.destroy("custom Player Destroy Reason", true);

destroys only the node and moves its players to different connected node.

player.node.destroy("custom Player Destroy Reason", true, true);

destroyPlayer(guildId: any): Promise<void>;

Defined in: src/structures/Node.ts:444

Destroys the Player on the Lavalink Server

ParameterTypeDescription
guildIdany

Promise<void>

request result

// use player.destroy() instead
player.node.destroyPlayer(player.guildId);

disconnect(disconnectReason?: string): void;

Defined in: src/structures/Node.ts:652

Disconnects the Node-Connection (Websocket)

ParameterTypeDescription
disconnectReason?stringDisconnect Reason to use when disconnecting Node

void

void

Also the node will not get re-connected again.

player.node.disconnect("Forcefully disconnect the connection to the node.");

fetchAllPlayers(): Promise<
| LavalinkPlayer[]
| InvalidLavalinkRestRequest>;

Defined in: src/structures/Node.ts:675

Gets all Players of a Node

Promise< | LavalinkPlayer[] | InvalidLavalinkRestRequest>

array of players inside of lavalink

const node = lavalink.nodes.get("NODEID");
const playersOfLavalink = await node?.fetchAllPlayers();

fetchConnectionMetrics(): Promise<NodeLinkConnectionMetrics>;

Defined in: src/structures/Node.ts:901

Request NodeLink connection metrics. https://nodelink.js.org/docs/differences#connection-metrics

Promise<NodeLinkConnectionMetrics>

the connection metrics of the node

const connectionMetrics = await player.node.fetchConnectionMetrics();

fetchInfo(): Promise<LavalinkInfo>;

Defined in: src/structures/Node.ts:931

Request Lavalink information.

Promise<LavalinkInfo>

lavalink info object

const lavalinkInfo = await player.node.fetchInfo();
const availablePlugins:string[] = lavalinkInfo.plugins.map(plugin => plugin.name);
const availableSources:string[] = lavalinkInfo.sourceManagers;

fetchPlayer(guildId: string): Promise<
| LavalinkPlayer
| InvalidLavalinkRestRequest>;

Defined in: src/structures/Node.ts:690

Gets specific Player Information

ParameterType
guildIdstring

Promise< | LavalinkPlayer | InvalidLavalinkRestRequest>

lavalink player object if player exists on lavalink

const node = lavalink.nodes.get("NODEID");
const playerInformation = await node?.fetchPlayer("guildId");

fetchStats(): Promise<BaseNodeStats>;

Defined in: src/structures/Node.ts:888

Request Lavalink statistics.

Promise<BaseNodeStats>

the lavalink node stats

const lavalinkStats = await player.node.fetchStats();

fetchVersion(): Promise<string>;

Defined in: src/structures/Node.ts:915

Request Lavalink version.

Promise<string>

the current used lavalink version

const lavalinkVersion = await player.node.fetchVersion();

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

Defined in: src/structures/Node.ts:1604

Get the current sponsorblocks for the sponsorblock plugin

ParameterTypeDescription
playerPlayerpassthrough the player

Promise<SponsorBlockSegment[]>

sponsorblock seggment from lavalink

// use it on the player via player.getSponsorBlock();
const sponsorBlockSegments = await player.node.getSponsorBlock(player);

lavaSearch(
query: LavaSearchQuery,
requestUser: unknown,
throwOnEmpty: boolean): Promise<
| LavaSearchResponse
| SearchResult>;

Defined in: src/structures/Node.ts:358

Search something using the lavaSearchPlugin (filtered searches by types)

ParameterTypeDefault valueDescription
queryLavaSearchQueryundefinedLavaSearchQuery Object
requestUserunknownundefinedRequest User for creating the player(s)
throwOnEmptybooleanfalseWhether to throw on an empty result or not

Promise< | LavaSearchResponse | SearchResult>

LavaSearchresult (SearchResult if link is provided)

// use player.search() instead
player.node.lavaSearch({ types: ["playlist", "album"], query: "Rick Astley", source: "spotify" }, interaction.user);

request(
endpoint: string,
modify: ModifyRequest,
parseAsText: true): Promise<string>;

Defined in: src/structures/Node.ts:251

Makes an API call to the Node. Should only be used for manual parsing like for not supported plugins

ParameterTypeDescription
endpointstringThe endpoint that we will make the call to
modifyModifyRequestUsed to modify the request before being sent
parseAsTexttrue-

Promise<string>

The returned data

player.node.request(`/loadtracks?identifier=Never gonna give you up`, (options) => options.method = "GET", false);
request(
endpoint: string,
modify?: ModifyRequest,
parseAsText?: false): Promise<any>;

Defined in: src/structures/Node.ts:252

Makes an API call to the Node. Should only be used for manual parsing like for not supported plugins

ParameterTypeDescription
endpointstringThe endpoint that we will make the call to
modify?ModifyRequestUsed to modify the request before being sent
parseAsText?false-

Promise<any>

The returned data

player.node.request(`/loadtracks?identifier=Never gonna give you up`, (options) => options.method = "GET", false);

search(
query: SearchQuery,
requestUser: unknown,
throwOnEmpty: boolean): Promise<SearchResult>;

Defined in: src/structures/Node.ts:280

Search something raw on the node, please note only add tracks to players of that node

ParameterTypeDefault valueDescription
querySearchQueryundefinedSearchQuery Object
requestUserunknownundefinedRequest User for creating the player(s)
throwOnEmptybooleanfalseWhether to throw on an empty result or not

Promise<SearchResult>

Searchresult

// use player.search() instead
player.node.search({ query: "Never gonna give you up by Rick Astley", source: "soundcloud" }, interaction.user);
player.node.search({ query: "https://deezer.com/track/123456789" }, interaction.user);

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

Defined in: src/structures/Node.ts:1622

Set the current sponsorblocks for the sponsorblock plugin

ParameterTypeDescription
playerPlayerpassthrough the player
segmentsSponsorBlockSegment[]-

Promise<void>

void

// use it on the player via player.setSponsorBlock();
const sponsorBlockSegments = await player.node.setSponsorBlock(player, ["sponsor", "selfpromo"]);

updatePlayer(data: PlayerUpdateInfo): Promise<LavalinkPlayer>;

Defined in: src/structures/Node.ts:403

Update the Player State on the Lavalink Server

ParameterTypeDescription
dataPlayerUpdateInfodata to send to lavalink and sync locally

Promise<LavalinkPlayer>

result from lavalink

// use player.search() instead
player.node.updatePlayer({ guildId: player.guildId, playerOptions: { paused: true } }); // example to pause it

updateSession(resuming?: boolean, timeout?: number): Promise<
| InvalidLavalinkRestRequest
| Session>;

Defined in: src/structures/Node.ts:707

Updates the session with and enables/disables resuming and timeout

ParameterTypeDescription
resuming?booleanWhether resuming is enabled for this session or not
timeout?numberThe timeout in seconds (default is 60s)

Promise< | InvalidLavalinkRestRequest | Session>

the result of the request

const node = player.node || lavalink.nodes.get("NODEID");
await node?.updateSession(true, 180e3); // will enable resuming for 180seconds