Node
Class representing a Lavalink node.
Signature
export declare class NodeJSDoc
Properties
20Methods
13Properties
readonly options: RequiredHoshimiNodeOptions;The options for the node.
readonly rest: RestStructure;The REST for the node.
readonly nodeManager: NodeManagerStructure;The manager for the node.
readonly lyricsManager: LyricsManagerStructure;The lyrics manager for the node.
readonly retryDelay: number;The delay between reconnect attempts.
retryAmount: number;The amount of reconnect attempts left.
ws: WebSocket | null;The WebSocket for the node.
state: State;The state of the node.
sessionId: string | null;The session id of the node.
reconnectTimeout: NodeJS.Timeout | null;The interval for the reconnect.
stats: Stats | null;The public stats of the node.
info: NodeInfo | null;The public info of the node.
heartbeatInterval: NodeJS.Timeout | null;Interval handle for the heartbeat ping.
isAlive: boolean;Whether the socket responded to the last ping. Set to false when a ping is sent, back to true when a pong arrives. If still false at the next ping, the socket is terminated.
session: NullableLavalinkSession;The session of the node.
readonly decode: DecodeMethods;The decode methods for the node.
idGetterget id(): string;The id of the node.
Examples
const node = manager.nodeManager.get("node1");
if (node) {
console.log(node.id); // node1
}addressGetterget address(): string;The socket address to connect the node.
Examples
```ts
const node = manager.nodeManager.get("node1");
if (node) {
console.log(node.id); // node1
console.log(node.address); // ws://localhost:2333/v4/websocket
}
}readyGetterget ready(): boolean;Check if the node is ready to receive events.
Examples
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");
}
}penaltiesGetterget penalties(): number;The penalties of the node.
Examples
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
}Methods
constructorConstructorconstructor(nodeManager: NodeManagerStructure, options: NodeOptions);message?(payload: unknown): Awaitable<void>;Define a custom event handler for the node.
Parameters
payload- The payload received from the node.
Returns
Examples
class CustomNode extends Node {
public async message(payload: any): Promise<void> {
console.log("Received payload:", payload);
}
}isNodelink(): boolean;Check if the node is a Nodelink node.
Returns
True if the node is a Nodelink node, false otherwise.
Examples
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");
}
}search(search: SearchQuery): Promise<LavalinkSearchResponse | null>;Search for a query.
Parameters
search- The query to search for.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) {
const search = await node.search({
query: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
source: SearchSources.Youtube,
});
console.log(search); // the search result
}connect(): void;Connect the node to the websocket.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) node.connect();stopPlayer(guildId: string): Promise<LavalinkPlayer | null>;Stop the track in player for the guild.
Parameters
guildId- The guild id to stop the player.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) {
const player = await node.stopPlayer("guildId");
console.log(player); // the lavalink player
}updatePlayer(data: Partial<UpdatePlayerInfo>): Promise<LavalinkPlayer | null>;Update the player data.
Parameters
data- The player data to update.
Returns
Examples
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
}destroyPlayer(guildId: string): Promise<void>;Destroy the player.
Parameters
guildId- The guild id to destroy the player.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) await node.destroyPlayer("guildId");
console.log("Player destroyed");disconnect(disconnect?: NodeDisconnectInfo): void;Disconnect the node from the websocket.
Parameters
disconnect- The disconnect options for the node.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) node.disconnect();
console.log("Node disconnected");destroy(destroy?: NodeDestroyInfo): void;Destroy the node.
Parameters
destroy- The destroy options for the node.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) node.destroy();
console.log("Node destroyed");updateSession(options: SessionResumingOptions): Promise<LavalinkSession | null>;Update the session for the node
Parameters
options- The session resuming options.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) {
const session = await node.updateSession({ resuming: true, timeout: 30000 });
console.log(session); // the lavalink session
}reconnect(): void;Reconnect the node.
Returns
Examples
const node = manager.nodeManager.get("node1");
if (node) node.reconnect();
console.log("Node reconnected");toJSON(): NodeJSON;Convert the node to JSON.
Returns
The JSON representation of the node.
Examples
const node = manager.nodeManager.get("node1");
if (node) {
const json = node.toJSON();
console.log(json);
}