Skip to main content
Version: v2.8.6 (current)

Class : Node

Constructor

new Magmastream.Node(options: NodeOptions)
Parameter Type Description Optional
hoststringThe host for the node.
portnumberThe port for the node.
passwordstringThe password for the node.
securebooleanWhether the host uses SSL.
identifierstringThe identifier for the node.
retryAmountnumberThe retryAmount for the node.
retryDelaynumberThe retryDelay for the node.
resumeStatusbooleanWhether to resume the previous session.
resumeTimeoutnumberThe time the lavalink server will wait before it removes the player.
requestTimeoutnumberThe timeout used for api calls.
prioritynumberPriority of the node.

Table of contents

Properties Methods
socketaddress()
statsconnected()
managerconnect()
sessionIdcreateSessionIdsFile()
restdeleteSponsorBlock()
infodestroy()
fetchInfo()
getLyrics()
getSponsorBlock()
loadSessionIds()
setSponsorBlock()
updateSessionId()

Properties

socket

The socket for the node.

Return: WebSocket | null


stats

The stats for the node.

Return: nodeStats{}


manager

The manager for the node.

Return: Manager


sessionId

The node's session ID.

Return: string | null


rest

readonly

The REST instance.

Return: Rest


info

Actual Lavalink information of the node.

Return: lavalinkInfo{} | null

Methods

address()

get

Returns the address for this node.

Return: string


connected()

get

Returns if connected to the Node.

Return: boolean


connect()

Connects to the Node.

If the node is already connected, this method will do nothing.
If the node has a session ID, it will be sent in the headers of the WebSocket connection.
If the node has no session ID but the resumeStatus option is true, it will use the session ID
stored in the sessionIds.json file if it exists.

Return: void


createSessionIdsFile()

Creates the sessionIds.json file if it doesn't exist. This file is used to store the session IDs for each node. The session IDs are used to identify the node when resuming a session.

Return: void


deleteSponsorBlock(player)

Deletes the sponsorblock segments for a player.

Return: Promise<void>

Parameter Type Description Optional
playerPlayerThe player to delete the sponsorblocks for.

destroy()

async function

Destroys the node and cleans up associated resources.

This method emits a debug event indicating that the node is being destroyed and attempts to automatically move all players connected to the node to a usable one. It then closes the WebSocket connection, removes all event listeners, and clears the reconnect timeout. Finally, it emits a "nodeDestroy" event and removes the node from the manager.

Return: Promise<void>


fetchInfo()

async function

Fetches Lavalink node information.

Return: Promise<lavalinkInfo{}>


getLyrics(track, skipTrackSource)

async function

Fetches the lyrics of a track from the Lavalink node.

This method uses the lavalyrics-plugin to fetch the lyrics. If the plugin is not available, it will throw a RangeError.

Return: Promise<lyrics{}>

Parameter Type Description Optional
tracktrack{}The track to fetch the lyrics for.
skipTrackSourcebooleanWhether to skip using the track's source URL.

getSponsorBlock(player)

async function

Gets the current sponsorblock segments for a player.

Return: Promise<sponsorBlockSegment[]>

Parameter Type Description Optional
playerPlayerThe player to get the sponsor blocks for.

loadSessionIds()

Loads session IDs from the sessionIds.json file if it exists. The session IDs are used to resume sessions for each node.

The session IDs are stored in the sessionIds.json file as a composite key of the node identifier and cluster ID. This allows multiple clusters to be used with the same node identifier.

Return: void


setSponsorBlock(player, segments)

async function

Updates the session ID in the sessionIds.json file.

This method is called after the session ID has been updated, and it writes the new session ID to the sessionIds.json file.

Return: Promise<void>

Parameter Type Description Optional
playerPlayerThe player to set the sponsor blocks for.
segments SponsorBlockSegment[]The sponsorblock segments to set. Defaults to ["sponsor", "selfpromo"] if not provided.

updateSessionId()

Updates the session ID in the sessionIds.json file.

This method is called after the session ID has been updated, and it writes the new session ID to the sessionIds.json file.

Return: void