Lavacord
    Preparing search index...

    Class LavalinkNode

    The LavalinkNode class handles the connection and communication with a Lavalink server.

    LavalinkNode instances are typically created and managed by the Manager class, which handles load balancing across multiple nodes and routing player actions to the appropriate node.

    Index

    Constructors

    Properties

    host: "localhost"

    The hostname or IP address of the Lavalink server.

    This can be a domain name, IPv4, or IPv6 address pointing to your Lavalink server.

    id: string

    The identifier for this Lavalink node. Used to distinguish between multiple nodes.

    This is a required property that must be unique across all nodes in your application. It's used for identifying this node in logs and when selecting nodes for new players.

    manager: Manager

    The Manager instance that controls this node

    password: "youshallnotpass"

    The password used for authorization with the Lavalink server.

    This password must match the one configured in your Lavalink server's application.yml. It's used in the Authorization header when establishing the WebSocket connection.

    port: string | number = 2333

    The port number that the Lavalink server is listening on.

    This should match the port configured in your Lavalink server's application.yml.

    reconnectInterval: number = 10000

    The time in milliseconds between reconnection attempts if the connection fails.

    Lower values will attempt reconnections more quickly, but might cause excessive connection attempts during prolonged server outages.

    resumeTimeout: number = 60

    The timeout in seconds after which a disconnected session can no longer be resumed.

    This value is sent to the Lavalink server when configuring session resuming. After this many seconds of disconnection, the session will be fully closed and cannot be resumed.

    resuming: boolean = false

    Whether this node should attempt to resume the session when reconnecting.

    When true, the node will try to resume the previous session after a disconnect, preserving player states and connections. This helps maintain playback during brief disconnections or node restarts.

    secure: false

    Whether to use secure connections (HTTPS/WSS) instead of HTTP/WS.

    When true, WebSocket connections will use WSS and REST requests will use HTTPS. This is required when connecting to Lavalink servers behind SSL/TLS.

    sessionId?: string

    The unique session identifier provided by Lavalink on successful connection.

    This ID is used for resuming sessions and in certain REST API calls. It's automatically assigned when connecting to the Lavalink server.

    state?: any

    Custom data that can be attached to the node instance.

    Not used internally by Lavacord, available for application-specific needs. You can use this property to store any data relevant to your implementation, such as region information, feature flags, or custom metrics.

    stats: Stats = ...

    The statistics received from the Lavalink server.

    Contains information about system resource usage, player counts, and audio frame statistics. This is updated whenever the Lavalink server sends a stats update (typically every minute). You can use these stats to implement node selection strategies in your application.

    version: string = "4"

    The version of the Lavalink protocol this node is using.

    This is set automatically when connecting to the Lavalink server. It indicates which version of the Lavalink protocol this node supports. The default value is "4", which corresponds to the latest stable version.

    "4"
    
    ws: BetterWs | null = null

    The WebSocket instance used for communication with the Lavalink server.

    When not connected to Lavalink, this property will be null. You can check the connected property to determine connection status.

    Accessors

    • get connected(): boolean

      Indicates whether this node is currently connected to the Lavalink server.

      Returns boolean

      true if connected, false otherwise

      Checks if the ws instance exists and if its ready state is 1. This property is useful for verifying connection status before attempting operations or implementing node selection strategies.

    • get restURL(): string

      Gets the REST API base URL for the Lavalink server.

      Returns string

      The complete REST API base URL including protocol, host, port, and path

      Returns either a secure (https://) or insecure (http://) REST URL based on the secure property configuration.

    • get socketURL(): string

      Gets the WebSocket URL for connecting to the Lavalink server.

      Returns string

      The complete WebSocket URL including protocol, host, port, and path

      Returns either a secure (wss://) or insecure (ws://) WebSocket URL based on the secure property configuration.

    Methods

    • Establishes a connection to the Lavalink server.

      This method creates a new WebSocket connection to the configured Lavalink server. If the node is already connected, it will close the existing connection first. The method sets up event listeners for the WebSocket to handle messages, errors, and connection state changes.

      Note: This method is primarily used internally by the Manager class. Users typically should not call this method directly as the Manager handles node connections automatically.

      Returns Promise<BetterWs>

      A promise that resolves when connected or rejects if connection fails

      If the connection fails due to network issues, authentication problems, or other errors

    • Gracefully closes the connection to the Lavalink server.

      This method closes the WebSocket connection with a normal closure code (1000) and a reason of "destroy", indicating an intentional disconnection rather than an error condition.

      Note: This method is primarily used internally by the Manager class. Users typically should not call this method directly as the Manager handles node disconnections automatically.

      Returns void

      void