lavalink-client 2.1.3 → 2.1.4

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.
@@ -6,10 +6,6 @@ import { DestroyReasonsType, Player, PlayerJson, PlayerOptions } from "./Player"
6
6
  import { ManagerQueueOptions } from "./Queue";
7
7
  import { Track, UnresolvedTrack } from "./Track";
8
8
  import { ChannelDeletePacket, GuildShardPayload, ManagerUtils, MiniMap, SearchPlatform, SponsorBlockChaptersLoaded, SponsorBlockChapterStarted, SponsorBlockSegmentSkipped, SponsorBlockSegmentsLoaded, TrackEndEvent, TrackExceptionEvent, TrackStartEvent, TrackStuckEvent, VoicePacket, VoiceServer, VoiceState, WebSocketClosedEvent } from "./Utils";
9
- export interface LavalinkManager {
10
- nodeManager: NodeManager;
11
- utils: ManagerUtils;
12
- }
13
9
  export interface BotClientOptions {
14
10
  /** Bot Client Id */
15
11
  id: string;
@@ -168,31 +164,186 @@ interface LavalinkManagerEvents {
168
164
  "ChaptersLoaded": (player: Player, track: Track | UnresolvedTrack, payload: SponsorBlockChaptersLoaded) => void;
169
165
  }
170
166
  export interface LavalinkManager {
171
- options: ManagerOptions;
167
+ /** @private */
172
168
  on<U extends keyof LavalinkManagerEvents>(event: U, listener: LavalinkManagerEvents[U]): this;
169
+ /** @private */
173
170
  emit<U extends keyof LavalinkManagerEvents>(event: U, ...args: Parameters<LavalinkManagerEvents[U]>): boolean;
174
171
  }
175
172
  export declare class LavalinkManager extends EventEmitter {
176
- static DefaultSources: Record<SearchPlatform, import("./Utils").LavalinkSearchPlatform | import("./Utils").ClientCustomSearchPlatformUtils>;
177
- static SourceLinksRegexes: Record<import("./Utils").SourcesRegex, RegExp>;
173
+ /** The Options of LavalinkManager (changeable) */
174
+ options: ManagerOptions;
175
+ /** LavalinkManager's NodeManager to manage all Nodes */
176
+ nodeManager: NodeManager;
177
+ /** LavalinkManager's Utils Class */
178
+ utils: ManagerUtils;
179
+ /** Wether the manager was initiated or not */
178
180
  initiated: boolean;
181
+ /** All Players stored in a MiniMap */
179
182
  readonly players: MiniMap<string, Player>;
183
+ /**
184
+ * Applies the options provided by the User
185
+ * @param options
186
+ * @returns
187
+ */
180
188
  private applyOptions;
189
+ /**
190
+ * Validates the current manager's options
191
+ * @param options
192
+ */
181
193
  private validateOptions;
194
+ /**
195
+ * Create the Lavalink Manager
196
+ * @param options
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * //const client = new Client({...}); // create your BOT Client (e.g. via discord.js)
201
+ * client.lavalink = new LavalinkManager({
202
+ * nodes: [
203
+ * {
204
+ * authorization: "yourverystrongpassword",
205
+ * host: "localhost",
206
+ * port: 2333,
207
+ * id: "testnode"
208
+ * },
209
+ * sendToShard(guildId, payload) => client.guilds.cache.get(guildId)?.shard?.send(payload),
210
+ * client: {
211
+ * id: process.env.CLIENT_ID,
212
+ * username: "TESTBOT"
213
+ * },
214
+ * // optional Options:
215
+ * autoSkip: true,
216
+ * playerOptions: {
217
+ * applyVolumeAsFilter: false,
218
+ * clientBasedPositionUpdateInterval: 150,
219
+ * defaultSearchPlatform: "ytmsearch",
220
+ * volumeDecrementer: 0.75,
221
+ * //requesterTransformer: YourRequesterTransformerFunction,
222
+ * onDisconnect: {
223
+ * autoReconnect: true,
224
+ * destroyPlayer: false
225
+ * },
226
+ * onEmptyQueue: {
227
+ * destroyAfterMs: 30_000,
228
+ * //autoPlayFunction: YourAutoplayFunction,
229
+ * },
230
+ * useUnresolvedData: true
231
+ * },
232
+ * queueOptions: {
233
+ * maxPreviousTracks: 25,
234
+ * //queueStore: yourCustomQueueStoreManagerClass,
235
+ * //queueChangesWatcher: yourCustomQueueChangesWatcherClass
236
+ * },
237
+ * linksBlacklist: [],
238
+ * linksWhitelist: [],
239
+ * advancedOptions: {
240
+ * debugOptions: {
241
+ * noAudio: false,
242
+ * playerDestroy: {
243
+ * dontThrowError: false,
244
+ * debugLogs: false
245
+ * }
246
+ * }
247
+ * }
248
+ * ]
249
+ * })
250
+ * ```
251
+ */
182
252
  constructor(options: ManagerOptions);
183
- createPlayer(options: PlayerOptions): Player;
253
+ /**
254
+ * Get a Player from Lava
255
+ * @param guildId The guildId of the player
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * const player = client.lavalink.getPlayer(interaction.guildId);
260
+ * ```
261
+ * A quicker and easier way than doing:
262
+ * ```ts
263
+ * const player = client.lavalink.players.get(interaction.guildId);
264
+ * ```
265
+ * @returns
266
+ */
184
267
  getPlayer(guildId: string): Player;
268
+ /**
269
+ * Create a Music-Player. If a player exists, then it returns it before creating a new one
270
+ * @param options
271
+ * @returns
272
+ *
273
+ * @example
274
+ * ```ts
275
+ * const player = client.lavalink.createPlayer({
276
+ * guildId: interaction.guildId,
277
+ * voiceChannelId: interaction.member.voice.channelId,
278
+ * // everything below is optional
279
+ * textChannelId: interaction.channelId,
280
+ * volume: 100,
281
+ * selfDeaf: true,
282
+ * selfMute: false,
283
+ * instaUpdateFiltersFix: true,
284
+ * applyVolumeAsFilter: false
285
+ * //only needed if you want to autopick node by region (configured by you)
286
+ * // vcRegion: interaction.member.voice.rtcRegion,
287
+ * // provide a specific node
288
+ * // node: client.lavalink.nodeManager.leastUsedNodes("memory")[0]
289
+ * });
290
+ * ```
291
+ */
292
+ createPlayer(options: PlayerOptions): Player;
293
+ /**
294
+ * Destroy a player with optional destroy reason and disconnect it from the voice channel
295
+ * @param guildId
296
+ * @param destroyReason
297
+ * @returns
298
+ *
299
+ * @example
300
+ * ```ts
301
+ * client.lavalink.destroyPlayer(interaction.guildId, "forcefully destroyed the player");
302
+ * // recommend to do it on the player tho: player.destroy("forcefully destroyed the player");
303
+ * ```
304
+ */
185
305
  destroyPlayer(guildId: string, destroyReason?: string): Promise<Player>;
306
+ /**
307
+ * Delete's a player from the cache without destroying it on lavalink (only works when it's disconnected)
308
+ * @param guildId
309
+ * @returns
310
+ */
186
311
  deletePlayer(guildId: string): boolean;
312
+ /**
313
+ * Checks wether the the lib is useable based on if any node is connected
314
+ */
187
315
  get useable(): boolean;
188
316
  /**
189
- * Initiates the Manager.
317
+ * Initiates the Manager, creates all nodes and connects all of them
190
318
  * @param clientData
319
+ *
320
+ * @example
321
+ *
322
+ * ```ts
323
+ * // on the bot ready event
324
+ * client.on("ready", () => {
325
+ * client.lavalink.init({
326
+ * id: client.user.id,
327
+ * username: client.user.username
328
+ * });
329
+ * });
330
+ * ```
191
331
  */
192
332
  init(clientData: BotClientOptions): Promise<this>;
193
333
  /**
194
334
  * Sends voice data to the Lavalink server.
335
+ * ! Without this the library won't work
195
336
  * @param data
337
+ *
338
+ * @example
339
+ *
340
+ * ```ts
341
+ * // on the bot "raw" event
342
+ * client.on("raw", (d) => {
343
+ * // required in order to send audio updates and register channel deletion etc.
344
+ * client.lavalink.sendRawData(d)
345
+ * })
346
+ * ```
196
347
  */
197
348
  sendRawData(data: VoicePacket | VoiceServer | VoiceState | ChannelDeletePacket): Promise<void>;
198
349
  }
@@ -172,7 +172,7 @@ export declare class Player {
172
172
  * @param query Query for your data
173
173
  * @param requestUser
174
174
  */
175
- search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").UnresolvedSearchResult | import("./Utils").SearchResult>;
175
+ search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
176
176
  /**
177
177
  * Pause the player
178
178
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lavalink-client",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
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",
@@ -14,7 +14,8 @@
14
14
  "lint": "eslint .",
15
15
  "lint:fix": "eslint --fix 'src/**/*.{ts}'",
16
16
  "format": "prettier --write src/**/*.ts --config ./.prettierrc.js",
17
- "test": "node -v"
17
+ "test": "node -v",
18
+ "docs": "npx typedoc"
18
19
  },
19
20
  "publishConfig": {
20
21
  "access": "public"
@@ -54,6 +55,8 @@
54
55
  "eslint": "^8.47.0",
55
56
  "ts-loader": "^9.4.4",
56
57
  "tslib": "^2.6.1",
58
+ "typedoc": "^0.25.4",
59
+ "typedoc-theme-hierarchy": "^4.1.2",
57
60
  "typescript": "^5.1.6"
58
61
  },
59
62
  "dependencies": {