hoshimi
    Preparing search index...

    Class Node

    Class representing a Lavalink node. Node

    Index

    Constructors

    • Create a new Lavalink node.

      Parameters

      Returns Node

      const node = new Node(nodeManager, {
      host: "localhost",
      port: 2333,
      password: "youshallnotpass",
      id: "node1",
      secure: false,
      retryAmount: 5,
      retryDelay: 20000,
      restTimeout: 10000,
      sessionId: null,
      });

      node.connect();
      console.log(node.id); // node1
      console.log(node.address); // ws://localhost:2333/v4/websocket
      console.log(node.penalties); // the penalties of the node
      console.log(node.state); // the state of the node

    Properties

    decode: DecodeMethods = ...

    The decode methods for the node.

    info: NodeInfo | null = null

    The public info of the node.

    lyricsManager: LyricsManager

    The lyrics manager for the node.

    nodeManager: NodeManager

    The manager for the node.

    options: Required<NodeOptions>

    The options for the node.

    reconnectTimeout: Timeout | null = null

    The interval for the reconnect.

    rest: Rest

    The REST for the node.

    retryAmount: number

    The amount of reconnect attempts left.

    retryDelay: number

    The delay between reconnect attempts.

    The session of the node.

    sessionId: string | null = null

    The session id of the node.

    state: State = State.Idle

    The state of the node.

    stats: Stats | null = null

    The public stats of the node.

    ws: WebSocket | null = null

    The WebSocket for the node.

    Accessors

    • get address(): string

      The socket address to connect the node.

      Returns string

      const node = manager.nodeManager.get("node1");
      if (node) {
      console.log(node.id); // node1
      console.log(node.address); // ws://localhost:2333/v4/websocket
      }
    • get id(): string

      The id of the node.

      Returns string

      const node = manager.nodeManager.get("node1");
      if (node) {
      console.log(node.id); // node1
      }
    • get penalties(): number

      The penalties of the node.

      Returns number

      const node = manager.nodeManager.get("node1");
      if (node) {
      console.log(node.id); // node1
      console.log(node.address); // ws://localhost:2333/v4/websocket
      console.log(node.penalties); // the penalties of the node
      }
    • get ready(): boolean

      Check if the node is ready to receive events.

      Returns boolean

      const node = manager.nodeManager.get("node1");
      if (node) {
      if (node.ready) {
      console.log("The node is ready");
      } else {
      console.log("The node is not ready");
      }
      }

    Methods

    • Connect the node to the websocket.

      Returns void

      If the client data is not valid

      const node = manager.nodeManager.get("node1");
      if (node) node.connect();
    • Destroy the player.

      Parameters

      • guildId: string

        The guild id to destroy the player.

      Returns Promise<void>

      const node = manager.nodeManager.get("node1");
      if (node) await node.destroyPlayer("guildId");
      console.log("Player destroyed");
    • Disconnect the node from the websocket.

      Parameters

      • Optionaldisconnect: NodeDestroyInfo = {}

        The disconnect options for the node.

      Returns void

      const node = manager.nodeManager.get("node1");
      if (node) node.disconnect();
      console.log("Node disconnected");
    • Check if the node is a Nodelink node.

      Returns boolean

      True if the node is a Nodelink node, false otherwise.

      const node = manager.nodeManager.get("node1");
      if (node) {
      if (node.isNodelink()) {
      console.log("The node is a Nodelink node");
      } else {
      console.log("The node is a Lavalink node");
      }
      }
    • Define a custom event handler for the node.

      Parameters

      • payload: unknown

        The payload to send to the node.

      Returns Awaitable<void>

      class CustomNode extends Node {
      public async message(payload: any): Promise<void> {
      console.log("Received payload:", payload);
      }
      }
    • Reconnect the node.

      Returns void

      If the node is not connected

      const node = manager.nodeManager.get("node1");
      if (node) node.reconnect();
      console.log("Node reconnected");
    • Stop the track in player for the guild.

      Parameters

      • guildId: string

        The guild id to stop the player.

      Returns Promise<LavalinkPlayer | null>

      const node = manager.nodeManager.get("node1");
      if (node) {
      const player = await node.stopPlayer("guildId");
      console.log(player); // the lavalink player
      }
    • Convert the node to JSON.

      Returns NodeJson

      The JSON representation of the node.

      const node = manager.nodeManager.get("node1");
      if (node) {
      const json = node.toJSON();
      console.log(json);
      }
    • Update the player data.

      Parameters

      Returns Promise<LavalinkPlayer | null>

      const node = manager.nodeManager.get("node1");
      if (node) {
      const player = await node.updatePlayer({
      guildId: "guildId",
      noReplace: true,
      playerOptions: {
      paused: false,
      track: { encoded: "encoded track" },
      },
      });

      console.log(player); // the lavalink player
      }