lavalink-client 1.1.22 → 1.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,14 @@ export interface ManagerOptions {
59
59
  /** optional */
60
60
  debugOptions?: {
61
61
  /** logs for debugging the "no-Audio" playing error */
62
- noAudio: boolean;
62
+ noAudio?: boolean;
63
+ /** For Logging the Destroy function */
64
+ playerDestroy?: {
65
+ /** To show the debug reason at all times. */
66
+ debugLog?: boolean;
67
+ /** If you get 'Error: Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player' put it on true */
68
+ dontThrowError?: boolean;
69
+ };
63
70
  };
64
71
  }
65
72
  interface LavalinkManagerEvents {
@@ -134,7 +141,7 @@ export declare class LavalinkManager extends EventEmitter {
134
141
  constructor(options: ManagerOptions);
135
142
  createPlayer(options: PlayerOptions): Player;
136
143
  getPlayer(guildId: string): Player;
137
- deletePlayer(guildId: string): boolean;
144
+ deletePlayer(guildId: string, throwError?: boolean): boolean;
138
145
  get useable(): boolean;
139
146
  /**
140
147
  * Initiates the Manager.
@@ -44,7 +44,11 @@ class LavalinkManager extends events_1.EventEmitter {
44
44
  queueStore: options?.queueOptions?.queueStore ?? new Queue_1.DefaultQueueStore(),
45
45
  },
46
46
  debugOptions: {
47
- noAudio: options?.debugOptions?.noAudio ?? false
47
+ noAudio: options?.debugOptions?.noAudio ?? false,
48
+ playerDestroy: {
49
+ dontThrowError: options?.debugOptions?.playerDestroy?.dontThrowError ?? false,
50
+ debugLog: options?.debugOptions?.playerDestroy?.debugLog ?? false,
51
+ }
48
52
  }
49
53
  };
50
54
  return;
@@ -87,8 +91,9 @@ class LavalinkManager extends events_1.EventEmitter {
87
91
  this.nodeManager = new NodeManager_1.NodeManager(this);
88
92
  }
89
93
  createPlayer(options) {
90
- if (this.players.has(options?.guildId))
91
- return this.players.get(options?.guildId);
94
+ const oldPlayer = this.getPlayer(options?.guildId);
95
+ if (oldPlayer)
96
+ return oldPlayer;
92
97
  const newPlayer = new Player_1.Player(options, this);
93
98
  this.players.set(newPlayer.guildId, newPlayer);
94
99
  return newPlayer;
@@ -96,9 +101,16 @@ class LavalinkManager extends events_1.EventEmitter {
96
101
  getPlayer(guildId) {
97
102
  return this.players.get(guildId);
98
103
  }
99
- deletePlayer(guildId) {
100
- if (typeof this.players.get(guildId)?.voiceChannelId === "string")
101
- throw new Error("Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player");
104
+ deletePlayer(guildId, throwError = true) {
105
+ const oldPlayer = this.getPlayer(guildId);
106
+ if (!oldPlayer)
107
+ return;
108
+ if (oldPlayer.voiceChannelId === "string" && oldPlayer.connected) {
109
+ if (throwError)
110
+ throw new Error(`Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player ${JSON.stringify(oldPlayer.toJSON?.())}`);
111
+ else
112
+ console.error("Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player", oldPlayer.toJSON?.());
113
+ }
102
114
  return this.players.delete(guildId);
103
115
  }
104
116
  get useable() {
@@ -177,6 +189,11 @@ class LavalinkManager extends events_1.EventEmitter {
177
189
  console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, No Lavalink Player found via key: 'guild_id' of update-data:", update);
178
190
  return;
179
191
  }
192
+ if (player.get("internal_destroystatus") === true) {
193
+ if (this.options?.debugOptions?.noAudio === true)
194
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Player is in a destroying state. can't signal the voice states");
195
+ return;
196
+ }
180
197
  if ("token" in update) {
181
198
  if (!player.node?.sessionId)
182
199
  throw new Error("Lavalink Node is either not ready or not up to date");
@@ -346,11 +346,27 @@ class Player {
346
346
  * Destroy the player and disconnect from the voice channel
347
347
  */
348
348
  async destroy(reason) {
349
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
350
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Destroy-Reason: ${String(reason)}`);
351
+ if (this.get("internal_destroystatus") === true) {
352
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
353
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Already destroying somewhere else..`);
354
+ return;
355
+ }
356
+ this.set("internal_destroystatus", true);
357
+ // disconnect player and set VoiceChannel to Null
349
358
  await this.disconnect(true);
359
+ // Destroy the queue
350
360
  await this.queue.utils.destroy();
351
- this.LavalinkManager.deletePlayer(this.guildId);
361
+ // delete the player from cache
362
+ this.LavalinkManager.deletePlayer(this.guildId, !this.LavalinkManager.options.debugOptions.playerDestroy.dontThrowError);
363
+ // destroy the player on lavalink side
352
364
  await this.node.destroyPlayer(this.guildId);
365
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
366
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Player got destroyed successfully`);
367
+ // emit the event
353
368
  this.LavalinkManager.emit("playerDestroy", this, reason);
369
+ // return smt
354
370
  return this;
355
371
  }
356
372
  /**
@@ -59,7 +59,14 @@ export interface ManagerOptions {
59
59
  /** optional */
60
60
  debugOptions?: {
61
61
  /** logs for debugging the "no-Audio" playing error */
62
- noAudio: boolean;
62
+ noAudio?: boolean;
63
+ /** For Logging the Destroy function */
64
+ playerDestroy?: {
65
+ /** To show the debug reason at all times. */
66
+ debugLog?: boolean;
67
+ /** If you get 'Error: Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player' put it on true */
68
+ dontThrowError?: boolean;
69
+ };
63
70
  };
64
71
  }
65
72
  interface LavalinkManagerEvents {
@@ -134,7 +141,7 @@ export declare class LavalinkManager extends EventEmitter {
134
141
  constructor(options: ManagerOptions);
135
142
  createPlayer(options: PlayerOptions): Player;
136
143
  getPlayer(guildId: string): Player;
137
- deletePlayer(guildId: string): boolean;
144
+ deletePlayer(guildId: string, throwError?: boolean): boolean;
138
145
  get useable(): boolean;
139
146
  /**
140
147
  * Initiates the Manager.
@@ -41,7 +41,11 @@ export class LavalinkManager extends EventEmitter {
41
41
  queueStore: options?.queueOptions?.queueStore ?? new DefaultQueueStore(),
42
42
  },
43
43
  debugOptions: {
44
- noAudio: options?.debugOptions?.noAudio ?? false
44
+ noAudio: options?.debugOptions?.noAudio ?? false,
45
+ playerDestroy: {
46
+ dontThrowError: options?.debugOptions?.playerDestroy?.dontThrowError ?? false,
47
+ debugLog: options?.debugOptions?.playerDestroy?.debugLog ?? false,
48
+ }
45
49
  }
46
50
  };
47
51
  return;
@@ -84,8 +88,9 @@ export class LavalinkManager extends EventEmitter {
84
88
  this.nodeManager = new NodeManager(this);
85
89
  }
86
90
  createPlayer(options) {
87
- if (this.players.has(options?.guildId))
88
- return this.players.get(options?.guildId);
91
+ const oldPlayer = this.getPlayer(options?.guildId);
92
+ if (oldPlayer)
93
+ return oldPlayer;
89
94
  const newPlayer = new Player(options, this);
90
95
  this.players.set(newPlayer.guildId, newPlayer);
91
96
  return newPlayer;
@@ -93,9 +98,16 @@ export class LavalinkManager extends EventEmitter {
93
98
  getPlayer(guildId) {
94
99
  return this.players.get(guildId);
95
100
  }
96
- deletePlayer(guildId) {
97
- if (typeof this.players.get(guildId)?.voiceChannelId === "string")
98
- throw new Error("Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player");
101
+ deletePlayer(guildId, throwError = true) {
102
+ const oldPlayer = this.getPlayer(guildId);
103
+ if (!oldPlayer)
104
+ return;
105
+ if (oldPlayer.voiceChannelId === "string" && oldPlayer.connected) {
106
+ if (throwError)
107
+ throw new Error(`Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player ${JSON.stringify(oldPlayer.toJSON?.())}`);
108
+ else
109
+ console.error("Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player", oldPlayer.toJSON?.());
110
+ }
99
111
  return this.players.delete(guildId);
100
112
  }
101
113
  get useable() {
@@ -174,6 +186,11 @@ export class LavalinkManager extends EventEmitter {
174
186
  console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, No Lavalink Player found via key: 'guild_id' of update-data:", update);
175
187
  return;
176
188
  }
189
+ if (player.get("internal_destroystatus") === true) {
190
+ if (this.options?.debugOptions?.noAudio === true)
191
+ console.debug("Lavalink-Client-Debug | NO-AUDIO [::] sendRawData function, Player is in a destroying state. can't signal the voice states");
192
+ return;
193
+ }
177
194
  if ("token" in update) {
178
195
  if (!player.node?.sessionId)
179
196
  throw new Error("Lavalink Node is either not ready or not up to date");
@@ -343,11 +343,27 @@ export class Player {
343
343
  * Destroy the player and disconnect from the voice channel
344
344
  */
345
345
  async destroy(reason) {
346
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
347
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Destroy-Reason: ${String(reason)}`);
348
+ if (this.get("internal_destroystatus") === true) {
349
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
350
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Already destroying somewhere else..`);
351
+ return;
352
+ }
353
+ this.set("internal_destroystatus", true);
354
+ // disconnect player and set VoiceChannel to Null
346
355
  await this.disconnect(true);
356
+ // Destroy the queue
347
357
  await this.queue.utils.destroy();
348
- this.LavalinkManager.deletePlayer(this.guildId);
358
+ // delete the player from cache
359
+ this.LavalinkManager.deletePlayer(this.guildId, !this.LavalinkManager.options.debugOptions.playerDestroy.dontThrowError);
360
+ // destroy the player on lavalink side
349
361
  await this.node.destroyPlayer(this.guildId);
362
+ if (this.LavalinkManager.options.debugOptions.playerDestroy.debugLog)
363
+ console.log(`Lavalink-Client-Debug | PlayerDestroy [::] destroy Function, [guildId ${this.guildId}] - Player got destroyed successfully`);
364
+ // emit the event
350
365
  this.LavalinkManager.emit("playerDestroy", this, reason);
366
+ // return smt
351
367
  return this;
352
368
  }
353
369
  /**
@@ -59,7 +59,14 @@ export interface ManagerOptions {
59
59
  /** optional */
60
60
  debugOptions?: {
61
61
  /** logs for debugging the "no-Audio" playing error */
62
- noAudio: boolean;
62
+ noAudio?: boolean;
63
+ /** For Logging the Destroy function */
64
+ playerDestroy?: {
65
+ /** To show the debug reason at all times. */
66
+ debugLog?: boolean;
67
+ /** If you get 'Error: Use Player#destroy(true) not PlayerManager#deletePlayer() to stop the Player' put it on true */
68
+ dontThrowError?: boolean;
69
+ };
63
70
  };
64
71
  }
65
72
  interface LavalinkManagerEvents {
@@ -134,7 +141,7 @@ export declare class LavalinkManager extends EventEmitter {
134
141
  constructor(options: ManagerOptions);
135
142
  createPlayer(options: PlayerOptions): Player;
136
143
  getPlayer(guildId: string): Player;
137
- deletePlayer(guildId: string): boolean;
144
+ deletePlayer(guildId: string, throwError?: boolean): boolean;
138
145
  get useable(): boolean;
139
146
  /**
140
147
  * Initiates the Manager.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "Easy, flexible and feature-rich lavalink@v4 Client. Both for Beginners and Proficients.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",