Skip to main content
Version: v2.7.5

Node

Constructor

new Magmastream.Node(options: NodeOptions)
Parameter Type Description
hoststringThe host for the node.
identifierstringThe identifier for the node.
passwordstringThe password for the node.
portnumberThe port for the node.
prioritynumberPriority of the node.
requestTimeoutnumberThe timeout used for api calls.
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.
securebooleanWhether the host uses SSL.

Table of contents

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

Properties

socket

The socket for the node.

Returns: WebSocket | null

stats

The stats for the node.

Returns: NodeStats

manager

The manager for the node.

Returns: Manager

sessionId

The node's session ID.

Returns: string | null

rest

readonly

The REST instance.

Returns: Rest

info

Actual Lavalink information of the node.

Returns: LavalinkInfo | null

Methods

address()

Returns the address for this node.

Returns: string

connected()

get

Returns if connected to the Node.

Returns: 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.

Returns: 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.

Returns: void

deleteSponsorBlock()

Deletes the sponsorblock segments for a player.

Returns: Promise<void>

Parameter Type Description
playerPlayerThe player to delete the sponsorblocks for.

destroy()

Destroys the Node and all players connected with it.

This method will:

  • Destroy all players connected to the node
  • Close the WebSocket connection
  • Remove all event listeners on the WebSocket
  • Clear the reconnect timeout
  • Emit a "nodeDestroy" event with the node as the argument
  • Destroy the node from the manager

Returns: void

extractSpotifyArtistID()

Extracts the Spotify artist ID from a URL.

Returns: string | null

Parameter Type Description
urlstringThe URL to extract the artist ID from.

extractSpotifyTrackID()

Extracts the Spotify track ID from a URL.

Returns: string | null

Parameter Type Description
urlstringThe URL to extract the artist ID from.

fetchInfo()

Fetches Lavalink node information.

Returns: Promise<LavalinkInfo>

getSponsorBlock()

Gets the current sponsorblock segments for a player.

Returns: Promise<SponsorBlockSegment[]>

Parameter Type Description
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.

Returns: void

setSponsorBlock()

Sets the sponsorblock segments for a player.

Returns: Promise<void>

Parameter Type Description
playerPlayerThe player to set the sponsor blocks for.
segmentsSponsorBlockSegment[]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.

Returns: void