LavalinkNode
Defined in: src/structures/Node.ts:26
Lavalink Node creator class
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LavalinkNode(options: LavalinkNodeOptions, manager: NodeManager): LavalinkNode;
Defined in: src/structures/Node.ts:93
Create a new Node
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
options | LavalinkNodeOptions | Lavalink Node Options |
manager | NodeManager | Node Manager |
Returns
Section titled “Returns”LavalinkNode
Example
Section titled “Example”// don't create a node manually, instead use:
client.lavalink.nodeManager.createNode(options)
Properties
Section titled “Properties”Property | Modifier | Type | Default value | Description | Defined in |
---|---|---|---|---|---|
calls | public | number | 0 | The amount of rest calls the node has made. | src/structures/Node.ts:38 |
decode | public | object | undefined | Decode Track or Tracks | src/structures/Node.ts:684 |
decode.multipleTracks | public | (encodeds : string [], requester : unknown ) => Promise <Track []> | undefined | Decodes 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:716 |
decode.singleTrack | public | (encoded : string , requester : unknown ) => Promise <Track > | undefined | Decode a single track into its info Example const encodedBase64 = 'QAACDgMACk5vIERpZ2dpdHkAC0JsYWNrc3RyZWV0AAAAAAAEo4AABjkxNjQ5NgABAB9odHRwczovL2RlZXplci5jb20vdHJhY2svOTE2NDk2AQBpaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvY292ZXIvZGFlN2EyNjViNzlmYjcxMjc4Y2RlMjUwNDg0OWQ2ZjcvMTAwMHgxMDAwLTAwMDAwMC04MC0wLTAuanBnAQAMVVNJUjE5NjAwOTc4AAZkZWV6ZXIBAChObyBEaWdnaXR5OiBUaGUgVmVyeSBCZXN0IE9mIEJsYWNrc3RyZWV0AQAjaHR0cHM6Ly93d3cuZGVlemVyLmNvbS9hbGJ1bS8xMDMyNTQBACJodHRwczovL3d3dy5kZWV6ZXIuY29tL2FydGlzdC8xODYxAQBqaHR0cHM6Ly9lLWNkbnMtaW1hZ2VzLmR6Y2RuLm5ldC9pbWFnZXMvYXJ0aXN0L2YxNmNhYzM2ZmVjMzkxZjczN2I3ZDQ4MmY1YWM3M2UzLzEwMDB4MTAwMC0wMDAwMDAtODAtMC0wLmpwZwEAT2h0dHBzOi8vY2RuLXByZXZpZXctYS5kemNkbi5uZXQvc3RyZWFtL2MtYTE1Yjg1NzFhYTYyMDBjMDQ0YmY1OWM3NmVkOTEyN2MtNi5tcDMAAAAAAAAAAAA='; const track = await player.node.decode.singleTrack(encodedBase64, interaction.user); | src/structures/Node.ts:697 |
info | public | LavalinkInfo | null | Actual Lavalink Information of the Node | src/structures/Node.ts:66 |
isAlive | public | boolean | false | - | src/structures/Node.ts:34 |
lyrics | public | object | undefined | - | src/structures/Node.ts:728 |
lyrics.get | public | (track : Track , skipTrackSource : boolean ) => Promise <LyricsResult > | undefined | Get 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:742 |
lyrics.getCurrent | public | (guildId : string , skipTrackSource : boolean ) => Promise <LyricsResult > | undefined | Get 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:771 |
lyrics.subscribe | public | (guildId : string ) => Promise <unknown > | undefined | subscribe 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:800 |
lyrics.unsubscribe | public | (guildId : string ) => Promise <void > | undefined | unsubscribe 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:828 |
options | public | LavalinkNodeOptions | undefined | The provided Options of the Node | src/structures/Node.ts:36 |
resuming | public | object | undefined | Wether the node resuming is enabled or not | src/structures/Node.ts:64 |
resuming.enabled | public | boolean | undefined | - | src/structures/Node.ts:64 |
resuming.timeout | public | number | undefined | - | src/structures/Node.ts:64 |
routePlannerApi | public | object | undefined | Lavalink’s Route Planner Api | src/structures/Node.ts:891 |
routePlannerApi.getStatus | public | () => Promise <RoutePlanner > | undefined | Get 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:903 |
routePlannerApi.unmarkAllFailedAddresses | public | () => Promise <unknown > | undefined | Release all blacklisted IP addresses into pool of IPs Example await player.node.routePlannerApi.unmarkAllFailedAddresses(); | src/structures/Node.ts:937 |
routePlannerApi.unmarkFailedAddress | public | (address : string ) => Promise <unknown > | undefined | Release blacklisted IP address into pool of IPs for ip rotation Example await player.node.routePlannerApi.unmarkFailedAddress("ipv6address"); | src/structures/Node.ts:918 |
sessionId? | public | string | null | The current sessionId, only present when connected | src/structures/Node.ts:62 |
stats | public | NodeStats | undefined | Stats from lavalink, will be updated via an interval by lavalink. | src/structures/Node.ts:40 |
Accessors
Section titled “Accessors”connected
Section titled “connected”Get Signature
Section titled “Get Signature”get connected(): boolean;
Defined in: src/structures/Node.ts:600
Returns if connected to the Node.
Example
Section titled “Example”const isConnected = player.node.connected;console.log("node is connected: ", isConnected ? "yes" : "no")
Returns
Section titled “Returns”boolean
connectionStatus
Section titled “connectionStatus”Get Signature
Section titled “Get Signature”get connectionStatus(): string;
Defined in: src/structures/Node.ts:617
Returns the current ConnectionStatus
Example
Section titled “Example”try { const statusOfConnection = player.node.connectionStatus; console.log("node's connection status is:", statusOfConnection)} catch (error) { console.error("no socket available?", error)}
Returns
Section titled “Returns”string
heartBeatPing
Section titled “heartBeatPing”Get Signature
Section titled “Get Signature”get heartBeatPing(): number;
Defined in: src/structures/Node.ts:29
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get id(): string;
Defined in: src/structures/Node.ts:461
Get the id of the node
Example
Section titled “Example”const nodeId = player.node.id;console.log("node id is: ", nodeId)
Returns
Section titled “Returns”string
Methods
Section titled “Methods”connect()
Section titled “connect()”connect(sessionId?: string): void;
Defined in: src/structures/Node.ts:387
Connect to the Lavalink Node
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
sessionId? | string | Provide the Session Id of the previous connection, to resume the node and it’s player(s) |
Returns
Section titled “Returns”void
void
Example
Section titled “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");
deleteSponsorBlock()
Section titled “deleteSponsorBlock()”deleteSponsorBlock(player: Player): Promise<void>;
Defined in: src/structures/Node.ts:1522
Delete the sponsorblock plugins
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
player | Player | passthrough the player |
Returns
Section titled “Returns”Promise
<void
>
void
Example
Section titled “Example”// use it on the player via player.deleteSponsorBlock();const sponsorBlockSegments = await player.node.deleteSponsorBlock(player);
destroy()
Section titled “destroy()”destroy( destroyReason?: string, deleteNode?: boolean, movePlayers?: boolean): void;
Defined in: src/structures/Node.ts:482
Destroys the Node-Connection (Websocket) and all player’s of the node
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
destroyReason? | string | undefined | Destroy Reason to use when destroying the players |
deleteNode? | boolean | true | wether to delete the nodte from the nodes list too, if false it will emit a disconnect. |
movePlayers? | boolean | false | whether to movePlayers to different eligible connected node. If false players won’t be moved |
Returns
Section titled “Returns”void
void
Default
Section titled “Default”true
Default
Section titled “Default”false
Example
Section titled “Example”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()
Section titled “destroyPlayer()”destroyPlayer(guildId: any): Promise<void>;
Defined in: src/structures/Node.ts:368
Destroys the Player on the Lavalink Server
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
guildId | any |
Returns
Section titled “Returns”Promise
<void
>
request result
Example
Section titled “Example”// use player.destroy() insteadplayer.node.destroyPlayer(player.guildId);
disconnect()
Section titled “disconnect()”disconnect(disconnectReason?: string): void;
Defined in: src/structures/Node.ts:578
Disconnects the Node-Connection (Websocket)
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
disconnectReason? | string | Disconnect Reason to use when disconnecting Node |
Returns
Section titled “Returns”void
void
Also the node will not get re-connected again.
Example
Section titled “Example”player.node.destroy("custom Player Destroy Reason", true);
fetchAllPlayers()
Section titled “fetchAllPlayers()”fetchAllPlayers(): Promise< | LavalinkPlayer[]| InvalidLavalinkRestRequest>;
Defined in: src/structures/Node.ts:632
Gets all Players of a Node
Returns
Section titled “Returns”Promise
<
| LavalinkPlayer
[]
| InvalidLavalinkRestRequest
>
array of players inside of lavalink
Example
Section titled “Example”const node = lavalink.nodes.get("NODEID");const playersOfLavalink = await node?.fetchAllPlayers();
fetchInfo()
Section titled “fetchInfo()”fetchInfo(): Promise<LavalinkInfo>;
Defined in: src/structures/Node.ts:884
Request Lavalink information.
Returns
Section titled “Returns”Promise
<LavalinkInfo
>
lavalink info object
Example
Section titled “Example”const lavalinkInfo = await player.node.fetchInfo();const availablePlugins:string[] = lavalinkInfo.plugins.map(plugin => plugin.name);const availableSources:string[] = lavalinkInfo.sourceManagers;
fetchPlayer()
Section titled “fetchPlayer()”fetchPlayer(guildId: string): Promise< | LavalinkPlayer| InvalidLavalinkRestRequest>;
Defined in: src/structures/Node.ts:647
Gets specific Player Information
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
guildId | string |
Returns
Section titled “Returns”Promise
<
| LavalinkPlayer
| InvalidLavalinkRestRequest
>
lavalink player object if player exists on lavalink
Example
Section titled “Example”const node = lavalink.nodes.get("NODEID");const playerInformation = await node?.fetchPlayer("guildId");
fetchStats()
Section titled “fetchStats()”fetchStats(): Promise<BaseNodeStats>;
Defined in: src/structures/Node.ts:855
Request Lavalink statistics.
Returns
Section titled “Returns”Promise
<BaseNodeStats
>
the lavalink node stats
Example
Section titled “Example”const lavalinkStats = await player.node.fetchStats();
fetchVersion()
Section titled “fetchVersion()”fetchVersion(): Promise<string>;
Defined in: src/structures/Node.ts:868
Request Lavalink version.
Returns
Section titled “Returns”Promise
<string
>
the current used lavalink version
Example
Section titled “Example”const lavalinkVersion = await player.node.fetchVersion();
getSponsorBlock()
Section titled “getSponsorBlock()”getSponsorBlock(player: Player): Promise<SponsorBlockSegment[]>;
Defined in: src/structures/Node.ts:1466
Get the current sponsorblocks for the sponsorblock plugin
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
player | Player | passthrough the player |
Returns
Section titled “Returns”Promise
<SponsorBlockSegment
[]>
sponsorblock seggment from lavalink
Example
Section titled “Example”// use it on the player via player.getSponsorBlock();const sponsorBlockSegments = await player.node.getSponsorBlock(player);
lavaSearch()
Section titled “lavaSearch()”lavaSearch( query: LavaSearchQuery, requestUser: unknown, throwOnEmpty: boolean): Promise< | LavaSearchResponse| SearchResult>;
Defined in: src/structures/Node.ts:278
Search something using the lavaSearchPlugin (filtered searches by types)
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
query | LavaSearchQuery | undefined | LavaSearchQuery Object |
requestUser | unknown | undefined | Request User for creating the player(s) |
throwOnEmpty | boolean | false | Wether to throw on an empty result or not |
Returns
Section titled “Returns”Promise
<
| LavaSearchResponse
| SearchResult
>
LavaSearchresult (SearchResult if link is provided)
Example
Section titled “Example”// use player.search() insteadplayer.node.lavaSearch({ types: ["playlist", "album"], query: "Rick Astley", source: "spotify" }, interaction.user);
request()
Section titled “request()”Call Signature
Section titled “Call Signature”request( endpoint: string, modify: ModifyRequest,parseAsText: true): Promise<string>;
Defined in: src/structures/Node.ts:172
Makes an API call to the Node. Should only be used for manual parsing like for not supported plugins
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
endpoint | string | The endpoint that we will make the call to |
modify | ModifyRequest | Used to modify the request before being sent |
parseAsText | true | - |
Returns
Section titled “Returns”Promise
<string
>
The returned data
Example
Section titled “Example”player.node.request(`/loadtracks?identifier=Never gonna give you up`, (options) => options.method = "GET", false);
Call Signature
Section titled “Call Signature”request( endpoint: string, modify?: ModifyRequest,parseAsText?: false): Promise<any>;
Defined in: src/structures/Node.ts:173
Makes an API call to the Node. Should only be used for manual parsing like for not supported plugins
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
endpoint | string | The endpoint that we will make the call to |
modify? | ModifyRequest | Used to modify the request before being sent |
parseAsText? | false | - |
Returns
Section titled “Returns”Promise
<any
>
The returned data
Example
Section titled “Example”player.node.request(`/loadtracks?identifier=Never gonna give you up`, (options) => options.method = "GET", false);
search()
Section titled “search()”search( query: SearchQuery, requestUser: unknown,throwOnEmpty: boolean): Promise<SearchResult>;
Defined in: src/structures/Node.ts:201
Search something raw on the node, please note only add tracks to players of that node
Parameters
Section titled “Parameters”Parameter | Type | Default value | Description |
---|---|---|---|
query | SearchQuery | undefined | SearchQuery Object |
requestUser | unknown | undefined | Request User for creating the player(s) |
throwOnEmpty | boolean | false | Wether to throw on an empty result or not |
Returns
Section titled “Returns”Promise
<SearchResult
>
Searchresult
Example
Section titled “Example”// use player.search() insteadplayer.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()
Section titled “setSponsorBlock()”setSponsorBlock(player: Player, segments: SponsorBlockSegment[]): Promise<void>;
Defined in: src/structures/Node.ts:1484
Set the current sponsorblocks for the sponsorblock plugin
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
player | Player | passthrough the player |
segments | SponsorBlockSegment [] | - |
Returns
Section titled “Returns”Promise
<void
>
void
Example
Section titled “Example”// use it on the player via player.setSponsorBlock();const sponsorBlockSegments = await player.node.setSponsorBlock(player, ["sponsor", "selfpromo"]);
updatePlayer()
Section titled “updatePlayer()”updatePlayer(data: PlayerUpdateInfo): Promise<LavalinkPlayer>;
Defined in: src/structures/Node.ts:325
Update the Player State on the Lavalink Server
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
data | PlayerUpdateInfo | data to send to lavalink and sync locally |
Returns
Section titled “Returns”Promise
<LavalinkPlayer
>
result from lavalink
Example
Section titled “Example”// use player.search() insteadplayer.node.updatePlayer({ guildId: player.guildId, playerOptions: { paused: true } }); // example to pause it
updateSession()
Section titled “updateSession()”updateSession(resuming?: boolean, timeout?: number): Promise< | InvalidLavalinkRestRequest| Session>;
Defined in: src/structures/Node.ts:664
Updates the session with and enables/disables resuming and timeout
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
resuming? | boolean | Whether resuming is enabled for this session or not |
timeout? | number | The timeout in seconds (default is 60s) |
Returns
Section titled “Returns”Promise
<
| InvalidLavalinkRestRequest
| Session
>
the result of the request
Example
Section titled “Example”const node = player.node || lavalink.nodes.get("NODEID");await node?.updateSession(true, 180e3); // will enable resuming for 180seconds