From 93be4929f14615a7ddf3e32dd0fd4381f9f8b7ca Mon Sep 17 00:00:00 2001 From: execaman <151807496+execaman@users.noreply.github.com> Date: Tue, 23 Jun 2026 13:08:34 +0530 Subject: [PATCH 1/3] feat(Player): make init nodes optional feat(Player): optional 'nodes' param for init() feat(Player): optional 'nodes' prop on player instance options --- src/main/player.ts | 11 ++--------- src/types/main/player.ts | 9 +++------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/player.ts b/src/main/player.ts index 07f457e..e05034c 100644 --- a/src/main/player.ts +++ b/src/main/player.ts @@ -7,7 +7,6 @@ import { Playlist, Queue, QueueManager, Track } from "@/queue"; import { EventEmitter } from "node:events"; import type { - CreateNodeOptions, CreateQueueOptions, MergeUnionType, PlayOptions, @@ -38,7 +37,6 @@ export class Player< #initPromise: Promise | null = null; #clientId: string | null = null; - #nodes: CreateNodeOptions[] | null = null; readonly options: PlayerInstanceOptions; readonly plugins: PluginRecord; @@ -52,12 +50,8 @@ export class Player< const _options = { ...DefaultPlayerOptions, ...options }; - if (_options.nodes.length === 0) throw new Error("Missing node create options"); if (typeof _options.forwardVoiceUpdate !== "function") throw new Error("Missing voice update function"); - this.#nodes = _options.nodes; - delete (_options as Partial).nodes; - this.options = _options; this.plugins = {} as PluginRecord; @@ -95,18 +89,17 @@ export class Player< return this.#clientId; } - async init(clientId: string) { + async init(clientId: string, nodes = this.options.nodes) { if (this.#initPromise !== null) return this.#initPromise; if (this.#initialized) return; const resolver = Promise.withResolvers(); this.#initPromise = resolver.promise; this.#clientId = clientId; try { - for (const node of this.#nodes!) this.nodes.create(node); + nodes?.forEach((node) => this.nodes.create(node)); for (const name in this.plugins) (this.plugins as { [x: string]: PlayerPlugin })[name]!.init(this); await this.nodes.connect(); this.#initialized = true; - this.#nodes = null; (this as Player).emit("init"); resolver.resolve(); } catch (err) { diff --git a/src/types/main/player.ts b/src/types/main/player.ts index 8052fc7..f290f63 100644 --- a/src/types/main/player.ts +++ b/src/types/main/player.ts @@ -65,9 +65,9 @@ export type PluginRecord = { */ export interface PlayerOptions { /** - * Options for creating node(s) + * Options for creating nodes on init */ - nodes: CreateNodeOptions[]; + nodes?: CreateNodeOptions[]; /** * Plugins to initialize after creating nodes @@ -114,10 +114,7 @@ export interface PlayerOptions fetchRelatedTracks?: (queue: Queue, track: Track) => Promise; } -export type PlayerInstanceOptions = Omit< - RequiredProp, - "nodes" | "plugins" ->; +export type PlayerInstanceOptions = Omit, "plugins">; /** * Voice state update payload From ed983d2defcaa1014d4d46471f9f6e95125a7410 Mon Sep 17 00:00:00 2001 From: execaman <151807496+execaman@users.noreply.github.com> Date: Tue, 23 Jun 2026 13:31:56 +0530 Subject: [PATCH 2/3] docs: update player options reference --- docs/src/content/docs/basics/player.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/content/docs/basics/player.mdx b/docs/src/content/docs/basics/player.mdx index 3fd9cd1..67c9420 100644 --- a/docs/src/content/docs/basics/player.mdx +++ b/docs/src/content/docs/basics/player.mdx @@ -18,7 +18,7 @@ Player | Option | Default | Description | | -------------------- | ------------ | -------------------------------------------------------------------------------------- | -| `nodes` | required | Array of node options | +| `nodes` | optional | Array of options for node creation on init | | `forwardVoiceUpdate` | required | Callback to send voice gateway payloads to Discord | | `autoInit` | `true` | Call `init()` automatically on Discord `READY` | | `autoSync` | `true` | Push local queue state to Lavalink when a node reconnects without resuming | From 4fff00db13c789c1db1a0bd24a293e14c89c0072 Mon Sep 17 00:00:00 2001 From: execaman <151807496+execaman@users.noreply.github.com> Date: Tue, 23 Jun 2026 13:41:57 +0530 Subject: [PATCH 3/3] refactor: negate undefined from default nodes param type for doc infer --- src/main/player.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/player.ts b/src/main/player.ts index e05034c..21f3430 100644 --- a/src/main/player.ts +++ b/src/main/player.ts @@ -89,7 +89,7 @@ export class Player< return this.#clientId; } - async init(clientId: string, nodes = this.options.nodes) { + async init(clientId: string, nodes = this.options.nodes!) { if (this.#initPromise !== null) return this.#initPromise; if (this.#initialized) return; const resolver = Promise.withResolvers();