Skip to content

LavalinkNode

Lavalink Node creator class

Constructors

new LavalinkNode()

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

Create a new Node

Parameters

ParameterTypeDescription
optionsLavalinkNodeOptionsLavalink Node Options
managerNodeManagerNode Manager

Returns

LavalinkNode

Example

// don't create a node manually, instead use:
client.lavalink.nodeManager.createNode(options)

Defined in

src/structures/Node.ts:86

Properties

PropertyModifierTypeDefault valueDescriptionDefined in
callspublicnumber0The amount of rest calls the node has made.src/structures/Node.ts:31
decodepublicobjectundefinedDecode Track or Trackssrc/structures/Node.ts:629
decode.multipleTrackspublic(encodeds: string[], requester: unknown) => Promise<Track[]>undefinedDecodes multiple tracks into their info Example const encodedBase64_1 = 'QAACDgMACk5vIERpZ2dpdHkAC0JsYWNrc3RyZWV0AAAAAAAEo4AABjkxNjQ5NgABAB9odHRwczovL2RlZXplci5jb20vdHJhY2svOTE2NDk2AQBpaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvY292ZXIvZGFlN2EyNjViNzlmYjcxMjc4Y2RlMjUwNDg0OWQ2ZjcvMTAwMHgxMDAwLTAwMDAwMC04MC0wLTAuanBnAQAMVVNJUjE5NjAwOTc4AAZkZWV6ZXIBAChObyBEaWdnaXR5OiBUaGUgVmVyeSBCZXN0IE9mIEJsYWNrc3RyZWV0AQAjaHR0cHM6Ly93d3cuZGVlemVyLmNvbS9hbGJ1bS8xMDMyNTQBACJodHRwczovL3d3dy5kZWV6ZXIuY29tL2FydGlzdC8xODYxAQBqaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvYXJ0aXN0L2YxNmNhYzM2ZmVjMzkxZjczN2I3ZDQ4MmY1YWM3M2UzLzEwMDB4MTAwMC0wMDAwMDAtODAtMC0wLmpwZwEAT2h0dHBzOi8vY2RuLXByZXZpZXctYS5kemNkbi5uZXQvc3RyZWFtL2MtYTE1Yjg1NzFhYTYyMDBjMDQ0YmY1OWM3NmVkOTEyN2MtNi5tcDMAAAAAAAAAAAA='; const encodedBase64_2 = 'QAABJAMAClRhbGsgYSBMb3QACjQwNHZpbmNlbnQAAAAAAAHr1gBxTzpodHRwczovL2FwaS12Mi5zb3VuZGNsb3VkLmNvbS9tZWRpYS9zb3VuZGNsb3VkOnRyYWNrczo4NTE0MjEwNzYvMzUyYTRiOTAtNzYxOS00M2E5LWJiOGItMjIxMzE0YzFjNjNhL3N0cmVhbS9obHMAAQAsaHR0cHM6Ly9zb3VuZGNsb3VkLmNvbS80MDR2aW5jZW50L3RhbGstYS1sb3QBADpodHRwczovL2kxLnNuZGNkbi5jb20vYXJ0d29ya3MtRTN1ek5Gc0Y4QzBXLTAtb3JpZ2luYWwuanBnAQAMUVpITkExOTg1Nzg0AApzb3VuZGNsb3VkAAAAAAAAAAA='; const tracks = await player.node.decode.multipleTracks([encodedBase64_1, encodedBase64_2], interaction.user);src/structures/Node.ts:661
decode.singleTrackpublic(encoded: string, requester: unknown) => Promise<Track>undefinedDecode a single track into its info Example const encodedBase64 = 'QAACDgMACk5vIERpZ2dpdHkAC0JsYWNrc3RyZWV0AAAAAAAEo4AABjkxNjQ5NgABAB9odHRwczovL2RlZXplci5jb20vdHJhY2svOTE2NDk2AQBpaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvY292ZXIvZGFlN2EyNjViNzlmYjcxMjc4Y2RlMjUwNDg0OWQ2ZjcvMTAwMHgxMDAwLTAwMDAwMC04MC0wLTAuanBnAQAMVVNJUjE5NjAwOTc4AAZkZWV6ZXIBAChObyBEaWdnaXR5OiBUaGUgVmVyeSBCZXN0IE9mIEJsYWNrc3RyZWV0AQAjaHR0cHM6Ly93d3cuZGVlemVyLmNvbS9hbGJ1bS8xMDMyNTQBACJodHRwczovL3d3dy5kZWV6ZXIuY29tL2FydGlzdC8xODYxAQBqaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvYXJ0aXN0L2YxNmNhYzM2ZmVjMzkxZjczN2I3ZDQ4MmY1YWM3M2UzLzEwMDB4MTAwMC0wMDAwMDAtODAtMC0wLmpwZwEAT2h0dHBzOi8vY2RuLXByZXZpZXctYS5kemNkbi5uZXQvc3RyZWFtL2MtYTE1Yjg1NzFhYTYyMDBjMDQ0YmY1OWM3NmVkOTEyN2MtNi5tcDMAAAAAAAAAAAA='; const track = await player.node.decode.singleTrack(encodedBase64, interaction.user);src/structures/Node.ts:642
infopublicLavalinkInfonullActual Lavalink Information of the Nodesrc/structures/Node.ts:59
isAlivepublicbooleanfalse-src/structures/Node.ts:27
lyricspublicobjectundefined-src/structures/Node.ts:673
lyrics.getpublic(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);src/structures/Node.ts:687
lyrics.getCurrentpublic(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();src/structures/Node.ts:716
lyrics.subscribepublic(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();src/structures/Node.ts:745
lyrics.unsubscribepublic(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();src/structures/Node.ts:773
optionspublicLavalinkNodeOptionsundefinedThe provided Options of the Nodesrc/structures/Node.ts:29
resumingpublicobjectundefinedWether the node resuming is enabled or notsrc/structures/Node.ts:57
resuming.enabledpublicbooleanundefined-src/structures/Node.ts:57
resuming.timeoutpublicnumberundefined-src/structures/Node.ts:57
routePlannerApipublicobjectundefinedLavalink’s Route Planner Apisrc/structures/Node.ts:836
routePlannerApi.getStatuspublic() => Promise<RoutePlanner>undefinedGet routplanner Info from Lavalink for ip rotation Example const routePlannerStatus = await player.node.routePlannerApi.getStatus(); const usedBlock = routePlannerStatus.details?.ipBlock; const currentIp = routePlannerStatus.currentAddress;src/structures/Node.ts:848
routePlannerApi.unmarkAllFailedAddressespublic() => Promise<unknown>undefinedRelease all blacklisted IP addresses into pool of IPs Example await player.node.routePlannerApi.unmarkAllFailedAddresses();src/structures/Node.ts:882
routePlannerApi.unmarkFailedAddresspublic(address: string) => Promise<unknown>undefinedRelease blacklisted IP address into pool of IPs for ip rotation Example await player.node.routePlannerApi.unmarkFailedAddress("ipv6address");src/structures/Node.ts:863
sessionId?publicstringnullThe current sessionId, only present when connectedsrc/structures/Node.ts:55
statspublicNodeStatsundefinedStats from lavalink, will be updated via an interval by lavalink.src/structures/Node.ts:33

Accessors

connected

get connected(): boolean

Returns if connected to the Node.

Example

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

Returns

boolean

Defined in

src/structures/Node.ts:545


connectionStatus

get connectionStatus(): string

Returns the current ConnectionStatus

Example

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

Returns

string

Defined in

src/structures/Node.ts:562


heartBeatPing

get heartBeatPing(): number

Returns

number

Defined in

src/structures/Node.ts:22


id

get id(): string

Get the id of the node

Example

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

Returns

string

Defined in

src/structures/Node.ts:472

Methods

connect()

connect(sessionId?: string): void

Connect to the Lavalink Node

Parameters

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

Returns

void

void

Example

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");

Defined in

src/structures/Node.ts:398


deleteSponsorBlock()

deleteSponsorBlock(player: Player): Promise<void>

Delete the sponsorblock plugins

Parameters

ParameterTypeDescription
playerPlayerpassthrough the player

Returns

Promise<void>

void

Example

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

Defined in

src/structures/Node.ts:1437


destroy()

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

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

Parameters

ParameterTypeDefault valueDescription
destroyReason?stringundefinedDestroy Reason to use when destroying the players
deleteNode?booleantruewether to delete the nodte from the nodes list too, if false it will emit a disconnect.

Returns

void

void

Default

true

Example

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

Defined in

src/structures/Node.ts:487


destroyPlayer()

destroyPlayer(guildId: any): Promise<void>

Destroys the Player on the Lavalink Server

Parameters

ParameterTypeDescription
guildIdany

Returns

Promise<void>

request result

Example

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

Defined in

src/structures/Node.ts:379


disconnect()

disconnect(disconnectReason?: string): void

Disconnects the Node-Connection (Websocket)

Parameters

ParameterTypeDescription
disconnectReason?stringDisconnect Reason to use when disconnecting Node

Returns

void

void

Also the node will not get re-connected again.

Example

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

Defined in

src/structures/Node.ts:523


fetchAllPlayers()

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

Gets all Players of a Node

Returns

Promise<LavalinkPlayer[] | InvalidLavalinkRestRequest>

array of players inside of lavalink

Example

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

Defined in

src/structures/Node.ts:577


fetchInfo()

fetchInfo(): Promise<LavalinkInfo>

Request Lavalink information.

Returns

Promise<LavalinkInfo>

lavalink info object

Example

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

Defined in

src/structures/Node.ts:829


fetchPlayer()

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

Gets specific Player Information

Parameters

ParameterType
guildIdstring

Returns

Promise<LavalinkPlayer | InvalidLavalinkRestRequest>

lavalink player object if player exists on lavalink

Example

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

Defined in

src/structures/Node.ts:592


fetchStats()

fetchStats(): Promise<BaseNodeStats>

Request Lavalink statistics.

Returns

Promise<BaseNodeStats>

the lavalink node stats

Example

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

Defined in

src/structures/Node.ts:800


fetchVersion()

fetchVersion(): Promise<string>

Request Lavalink version.

Returns

Promise<string>

the current used lavalink version

Example

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

Defined in

src/structures/Node.ts:813


getSponsorBlock()

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

Get the current sponsorblocks for the sponsorblock plugin

Parameters

ParameterTypeDescription
playerPlayerpassthrough the player

Returns

Promise<SponsorBlockSegment[]>

sponsorblock seggment from lavalink

Example

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

Defined in

src/structures/Node.ts:1383


lavaSearch()

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

Search something using the lavaSearchPlugin (filtered searches by types)

Parameters

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

Returns

Promise<LavaSearchResponse | SearchResult>

LavaSearchresult (SearchResult if link is provided)

Example

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

Defined in

src/structures/Node.ts:289


request()

request(endpoint, modify, parseAsText)

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

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

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

Promise<string>

The returned data

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

src/structures/Node.ts:187

request(endpoint, modify, parseAsText)

request(
endpoint: string,
modify?: ModifyRequest,
parseAsText?: false): Promise<any>
Parameters
ParameterType
endpointstring
modify?ModifyRequest
parseAsText?false
Returns

Promise<any>

Defined in

src/structures/Node.ts:188


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

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

Parameters

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

Returns

Promise<SearchResult>

Searchresult

Example

// 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);

Defined in

src/structures/Node.ts:215


setSponsorBlock()

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

Set the current sponsorblocks for the sponsorblock plugin

Parameters

ParameterTypeDescription
playerPlayerpassthrough the player
segmentsSponsorBlockSegment[]-

Returns

Promise<void>

void

Example

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

Defined in

src/structures/Node.ts:1401


updatePlayer()

updatePlayer(data: PlayerUpdateInfo): Promise<LavalinkPlayer>

Update the Player State on the Lavalink Server

Parameters

ParameterTypeDescription
dataPlayerUpdateInfodata to send to lavalink and sync locally

Returns

Promise<LavalinkPlayer>

result from lavalink

Example

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

Defined in

src/structures/Node.ts:336


updateSession()

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

Updates the session with and enables/disables resuming and timeout

Parameters

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

Returns

Promise<InvalidLavalinkRestRequest | Session>

the result of the request

Example

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

Defined in

src/structures/Node.ts:609