lavalink-client 2.1.3 → 2.1.5
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.
- package/README.md +92 -2
- package/dist/cjs/structures/Filters.d.ts +8 -8
- package/dist/cjs/structures/Filters.js +12 -12
- package/dist/cjs/structures/LavalinkManager.d.ts +160 -9
- package/dist/cjs/structures/LavalinkManager.js +160 -7
- package/dist/cjs/structures/Player.d.ts +3 -3
- package/dist/cjs/structures/Player.js +12 -6
- package/dist/esm/structures/Filters.d.ts +8 -8
- package/dist/esm/structures/Filters.js +12 -12
- package/dist/esm/structures/LavalinkManager.d.ts +160 -9
- package/dist/esm/structures/LavalinkManager.js +160 -7
- package/dist/esm/structures/Player.d.ts +3 -3
- package/dist/esm/structures/Player.js +12 -6
- package/dist/types/structures/Filters.d.ts +8 -8
- package/dist/types/structures/LavalinkManager.d.ts +160 -9
- package/dist/types/structures/Player.d.ts +3 -3
- package/package.json +5 -2
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { EventEmitter } from "events";
|
|
2
|
-
import { DefaultSources, SourceLinksRegexes } from "./LavalinkManagerStatics";
|
|
3
2
|
import { NodeManager } from "./NodeManager";
|
|
4
3
|
import { DestroyReasons, Player } from "./Player";
|
|
5
4
|
import { DefaultQueueStore } from "./Queue";
|
|
6
5
|
import { ManagerUtils, MiniMap } from "./Utils";
|
|
7
6
|
export class LavalinkManager extends EventEmitter {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/** The Options of LavalinkManager (changeable) */
|
|
8
|
+
options;
|
|
9
|
+
/** LavalinkManager's NodeManager to manage all Nodes */
|
|
10
|
+
nodeManager;
|
|
11
|
+
/** LavalinkManager's Utils Class */
|
|
12
|
+
utils;
|
|
13
|
+
/** Wether the manager was initiated or not */
|
|
10
14
|
initiated = false;
|
|
15
|
+
/** All Players stored in a MiniMap */
|
|
11
16
|
players = new MiniMap();
|
|
17
|
+
/**
|
|
18
|
+
* Applies the options provided by the User
|
|
19
|
+
* @param options
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
12
22
|
applyOptions(options) {
|
|
13
23
|
this.options = {
|
|
14
24
|
client: {
|
|
@@ -56,6 +66,10 @@ export class LavalinkManager extends EventEmitter {
|
|
|
56
66
|
};
|
|
57
67
|
return;
|
|
58
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Validates the current manager's options
|
|
71
|
+
* @param options
|
|
72
|
+
*/
|
|
59
73
|
validateOptions(options) {
|
|
60
74
|
if (typeof options?.sendToShard !== "function")
|
|
61
75
|
throw new SyntaxError("ManagerOption.sendToShard was not provided, which is required!");
|
|
@@ -86,6 +100,64 @@ export class LavalinkManager extends EventEmitter {
|
|
|
86
100
|
if (typeof options?.queueOptions?.maxPreviousTracks !== "number" || options?.queueOptions?.maxPreviousTracks < 0)
|
|
87
101
|
options.queueOptions.maxPreviousTracks = 25;
|
|
88
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Create the Lavalink Manager
|
|
105
|
+
* @param options
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* //const client = new Client({...}); // create your BOT Client (e.g. via discord.js)
|
|
110
|
+
* client.lavalink = new LavalinkManager({
|
|
111
|
+
* nodes: [
|
|
112
|
+
* {
|
|
113
|
+
* authorization: "yourverystrongpassword",
|
|
114
|
+
* host: "localhost",
|
|
115
|
+
* port: 2333,
|
|
116
|
+
* id: "testnode"
|
|
117
|
+
* },
|
|
118
|
+
* sendToShard(guildId, payload) => client.guilds.cache.get(guildId)?.shard?.send(payload),
|
|
119
|
+
* client: {
|
|
120
|
+
* id: process.env.CLIENT_ID,
|
|
121
|
+
* username: "TESTBOT"
|
|
122
|
+
* },
|
|
123
|
+
* // optional Options:
|
|
124
|
+
* autoSkip: true,
|
|
125
|
+
* playerOptions: {
|
|
126
|
+
* applyVolumeAsFilter: false,
|
|
127
|
+
* clientBasedPositionUpdateInterval: 150,
|
|
128
|
+
* defaultSearchPlatform: "ytmsearch",
|
|
129
|
+
* volumeDecrementer: 0.75,
|
|
130
|
+
* //requesterTransformer: YourRequesterTransformerFunction,
|
|
131
|
+
* onDisconnect: {
|
|
132
|
+
* autoReconnect: true,
|
|
133
|
+
* destroyPlayer: false
|
|
134
|
+
* },
|
|
135
|
+
* onEmptyQueue: {
|
|
136
|
+
* destroyAfterMs: 30_000,
|
|
137
|
+
* //autoPlayFunction: YourAutoplayFunction,
|
|
138
|
+
* },
|
|
139
|
+
* useUnresolvedData: true
|
|
140
|
+
* },
|
|
141
|
+
* queueOptions: {
|
|
142
|
+
* maxPreviousTracks: 25,
|
|
143
|
+
* //queueStore: yourCustomQueueStoreManagerClass,
|
|
144
|
+
* //queueChangesWatcher: yourCustomQueueChangesWatcherClass
|
|
145
|
+
* },
|
|
146
|
+
* linksBlacklist: [],
|
|
147
|
+
* linksWhitelist: [],
|
|
148
|
+
* advancedOptions: {
|
|
149
|
+
* debugOptions: {
|
|
150
|
+
* noAudio: false,
|
|
151
|
+
* playerDestroy: {
|
|
152
|
+
* dontThrowError: false,
|
|
153
|
+
* debugLogs: false
|
|
154
|
+
* }
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ]
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
89
161
|
constructor(options) {
|
|
90
162
|
super();
|
|
91
163
|
if (!options)
|
|
@@ -97,6 +169,47 @@ export class LavalinkManager extends EventEmitter {
|
|
|
97
169
|
// create classes
|
|
98
170
|
this.nodeManager = new NodeManager(this);
|
|
99
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Get a Player from Lava
|
|
174
|
+
* @param guildId The guildId of the player
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* const player = client.lavalink.getPlayer(interaction.guildId);
|
|
179
|
+
* ```
|
|
180
|
+
* A quicker and easier way than doing:
|
|
181
|
+
* ```ts
|
|
182
|
+
* const player = client.lavalink.players.get(interaction.guildId);
|
|
183
|
+
* ```
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
186
|
+
getPlayer(guildId) {
|
|
187
|
+
return this.players.get(guildId);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Create a Music-Player. If a player exists, then it returns it before creating a new one
|
|
191
|
+
* @param options
|
|
192
|
+
* @returns
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```ts
|
|
196
|
+
* const player = client.lavalink.createPlayer({
|
|
197
|
+
* guildId: interaction.guildId,
|
|
198
|
+
* voiceChannelId: interaction.member.voice.channelId,
|
|
199
|
+
* // everything below is optional
|
|
200
|
+
* textChannelId: interaction.channelId,
|
|
201
|
+
* volume: 100,
|
|
202
|
+
* selfDeaf: true,
|
|
203
|
+
* selfMute: false,
|
|
204
|
+
* instaUpdateFiltersFix: true,
|
|
205
|
+
* applyVolumeAsFilter: false
|
|
206
|
+
* //only needed if you want to autopick node by region (configured by you)
|
|
207
|
+
* // vcRegion: interaction.member.voice.rtcRegion,
|
|
208
|
+
* // provide a specific node
|
|
209
|
+
* // node: client.lavalink.nodeManager.leastUsedNodes("memory")[0]
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
100
213
|
createPlayer(options) {
|
|
101
214
|
const oldPlayer = this.getPlayer(options?.guildId);
|
|
102
215
|
if (oldPlayer)
|
|
@@ -105,15 +218,29 @@ export class LavalinkManager extends EventEmitter {
|
|
|
105
218
|
this.players.set(newPlayer.guildId, newPlayer);
|
|
106
219
|
return newPlayer;
|
|
107
220
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Destroy a player with optional destroy reason and disconnect it from the voice channel
|
|
223
|
+
* @param guildId
|
|
224
|
+
* @param destroyReason
|
|
225
|
+
* @returns
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* client.lavalink.destroyPlayer(interaction.guildId, "forcefully destroyed the player");
|
|
230
|
+
* // recommend to do it on the player tho: player.destroy("forcefully destroyed the player");
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
111
233
|
destroyPlayer(guildId, destroyReason) {
|
|
112
234
|
const oldPlayer = this.getPlayer(guildId);
|
|
113
235
|
if (!oldPlayer)
|
|
114
236
|
return;
|
|
115
237
|
return oldPlayer.destroy(destroyReason);
|
|
116
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Delete's a player from the cache without destroying it on lavalink (only works when it's disconnected)
|
|
241
|
+
* @param guildId
|
|
242
|
+
* @returns
|
|
243
|
+
*/
|
|
117
244
|
deletePlayer(guildId) {
|
|
118
245
|
const oldPlayer = this.getPlayer(guildId);
|
|
119
246
|
if (!oldPlayer)
|
|
@@ -127,12 +254,27 @@ export class LavalinkManager extends EventEmitter {
|
|
|
127
254
|
}
|
|
128
255
|
return this.players.delete(guildId);
|
|
129
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Checks wether the the lib is useable based on if any node is connected
|
|
259
|
+
*/
|
|
130
260
|
get useable() {
|
|
131
261
|
return this.nodeManager.nodes.filter(v => v.connected).size > 0;
|
|
132
262
|
}
|
|
133
263
|
/**
|
|
134
|
-
* Initiates the Manager
|
|
264
|
+
* Initiates the Manager, creates all nodes and connects all of them
|
|
135
265
|
* @param clientData
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
*
|
|
269
|
+
* ```ts
|
|
270
|
+
* // on the bot ready event
|
|
271
|
+
* client.on("ready", () => {
|
|
272
|
+
* client.lavalink.init({
|
|
273
|
+
* id: client.user.id,
|
|
274
|
+
* username: client.user.username
|
|
275
|
+
* });
|
|
276
|
+
* });
|
|
277
|
+
* ```
|
|
136
278
|
*/
|
|
137
279
|
async init(clientData) {
|
|
138
280
|
if (this.initiated)
|
|
@@ -162,7 +304,18 @@ export class LavalinkManager extends EventEmitter {
|
|
|
162
304
|
}
|
|
163
305
|
/**
|
|
164
306
|
* Sends voice data to the Lavalink server.
|
|
307
|
+
* ! Without this the library won't work
|
|
165
308
|
* @param data
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
*
|
|
312
|
+
* ```ts
|
|
313
|
+
* // on the bot "raw" event
|
|
314
|
+
* client.on("raw", (d) => {
|
|
315
|
+
* // required in order to send audio updates and register channel deletion etc.
|
|
316
|
+
* client.lavalink.sendRawData(d)
|
|
317
|
+
* })
|
|
318
|
+
* ```
|
|
166
319
|
*/
|
|
167
320
|
async sendRawData(data) {
|
|
168
321
|
if (!this.initiated) {
|
|
@@ -84,7 +84,7 @@ export interface LavalinkPlayOptions extends BasePlayOptions {
|
|
|
84
84
|
export interface PlayOptions extends LavalinkPlayOptions {
|
|
85
85
|
/** Whether to not replace the track if a play payload is sent. */
|
|
86
86
|
noReplace?: boolean;
|
|
87
|
-
/**
|
|
87
|
+
/** Adds track on queue and skips to it */
|
|
88
88
|
clientTrack?: Track | UnresolvedTrack;
|
|
89
89
|
}
|
|
90
90
|
export interface Player {
|
|
@@ -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").
|
|
175
|
+
search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
|
|
176
176
|
/**
|
|
177
177
|
* Pause the player
|
|
178
178
|
*/
|
|
@@ -195,7 +195,7 @@ export declare class Player {
|
|
|
195
195
|
* Skip the current song, or a specific amount of songs
|
|
196
196
|
* @param amount provide the index of the next track to skip to
|
|
197
197
|
*/
|
|
198
|
-
skip(skipTo?: number, throwError?: boolean):
|
|
198
|
+
skip(skipTo?: number, throwError?: boolean): any;
|
|
199
199
|
/**
|
|
200
200
|
* Clears the queue and stops playing. Does not destroy the Player and not leave the channel
|
|
201
201
|
* @returns
|
|
@@ -124,6 +124,7 @@ export class Player {
|
|
|
124
124
|
clearTimeout(this.get("internal_queueempty"));
|
|
125
125
|
this.set("internal_queueempty", undefined);
|
|
126
126
|
}
|
|
127
|
+
let replaced = false;
|
|
127
128
|
// if clientTrack provided, play it
|
|
128
129
|
if (options?.clientTrack && (this.LavalinkManager.utils.isTrack(options?.clientTrack) || this.LavalinkManager.utils.isUnresolvedTrack(options.clientTrack))) {
|
|
129
130
|
if (this.LavalinkManager.utils.isUnresolvedTrack(options.clientTrack))
|
|
@@ -131,16 +132,18 @@ export class Player {
|
|
|
131
132
|
if (typeof options.track.userData === "object")
|
|
132
133
|
options.clientTrack.userData = { ...(options?.clientTrack.userData || {}), ...(options.track.userData || {}) };
|
|
133
134
|
await this.queue.add(options?.clientTrack, 0);
|
|
134
|
-
await
|
|
135
|
+
return await this.skip();
|
|
135
136
|
}
|
|
136
137
|
else if (options?.track?.encoded) {
|
|
137
138
|
// handle play encoded options manually // TODO let it resolve by lavalink!
|
|
138
139
|
const track = await this.node.decode.singleTrack(options.track?.encoded, options.track?.requester || this.queue?.current?.requester || this.queue.previous?.[0]?.requester || this.queue.tracks?.[0]?.requester || this.LavalinkManager.options.client);
|
|
139
140
|
if (typeof options.track.userData === "object")
|
|
140
141
|
track.userData = { ...(track.userData || {}), ...(options.track.userData || {}) };
|
|
141
|
-
if (track)
|
|
142
|
+
if (track) {
|
|
143
|
+
replaced = true;
|
|
142
144
|
this.queue.add(track, 0);
|
|
143
|
-
|
|
145
|
+
await queueTrackEnd(this);
|
|
146
|
+
}
|
|
144
147
|
}
|
|
145
148
|
else if (options?.track?.identifier) {
|
|
146
149
|
// handle play identifier options manually // TODO let it resolve by lavalink!
|
|
@@ -149,9 +152,11 @@ export class Player {
|
|
|
149
152
|
}, options?.track?.identifier || this.queue?.current?.requester || this.queue.previous?.[0]?.requester || this.queue.tracks?.[0]?.requester || this.LavalinkManager.options.client);
|
|
150
153
|
if (typeof options.track.userData === "object")
|
|
151
154
|
res.tracks[0].userData = { ...(res.tracks[0].userData || {}), ...(options.track.userData || {}) };
|
|
152
|
-
if (res.tracks[0])
|
|
155
|
+
if (res.tracks[0]) {
|
|
156
|
+
replaced = true;
|
|
153
157
|
this.queue.add(res.tracks[0], 0);
|
|
154
|
-
|
|
158
|
+
await queueTrackEnd(this);
|
|
159
|
+
}
|
|
155
160
|
}
|
|
156
161
|
if (!this.queue.current && this.queue.tracks.length)
|
|
157
162
|
await queueTrackEnd(this);
|
|
@@ -208,7 +213,7 @@ export class Player {
|
|
|
208
213
|
const now = performance.now();
|
|
209
214
|
await this.node.updatePlayer({
|
|
210
215
|
guildId: this.guildId,
|
|
211
|
-
noReplace: options?.noReplace ?? false,
|
|
216
|
+
noReplace: replaced ? replaced : (options?.noReplace ?? false),
|
|
212
217
|
playerOptions: finalOptions,
|
|
213
218
|
});
|
|
214
219
|
this.ping.lavalink = Math.round((performance.now() - now) / 10) / 100;
|
|
@@ -464,6 +469,7 @@ export class Player {
|
|
|
464
469
|
paused: data.paused,
|
|
465
470
|
filters: { ...data.filters, equalizer: data.equalizer },
|
|
466
471
|
voice: this.voice,
|
|
472
|
+
track: this.queue.current ?? undefined
|
|
467
473
|
// track: this.queue.current,
|
|
468
474
|
},
|
|
469
475
|
});
|
|
@@ -61,27 +61,27 @@ export declare class FilterManager {
|
|
|
61
61
|
*/
|
|
62
62
|
setRate(rate?: number): Promise<boolean>;
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* Enables / Disables the rotation effect, (Optional: provide your Own Data)
|
|
65
65
|
* @param rotationHz
|
|
66
66
|
* @returns
|
|
67
67
|
*/
|
|
68
68
|
toggleRotation(rotationHz?: number): Promise<boolean>;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Enables / Disables the Vibrato effect, (Optional: provide your Own Data)
|
|
71
71
|
* @param frequency
|
|
72
72
|
* @param depth
|
|
73
73
|
* @returns
|
|
74
74
|
*/
|
|
75
75
|
toggleVibrato(frequency?: number, depth?: number): Promise<boolean>;
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Enables / Disables the Tremolo effect, (Optional: provide your Own Data)
|
|
78
78
|
* @param frequency
|
|
79
79
|
* @param depth
|
|
80
80
|
* @returns
|
|
81
81
|
*/
|
|
82
82
|
toggleTremolo(frequency?: number, depth?: number): Promise<boolean>;
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* Enables / Disables the LowPass effect, (Optional: provide your Own Data)
|
|
85
85
|
* @param smoothing
|
|
86
86
|
* @returns
|
|
87
87
|
*/
|
|
@@ -94,14 +94,14 @@ export declare class FilterManager {
|
|
|
94
94
|
};
|
|
95
95
|
lavalinkFilterPlugin: {
|
|
96
96
|
/**
|
|
97
|
-
*
|
|
97
|
+
* Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
|
|
98
98
|
* @param delay
|
|
99
99
|
* @param decay
|
|
100
100
|
* @returns
|
|
101
101
|
*/
|
|
102
102
|
toggleEcho: (delay?: number, decay?: number) => Promise<boolean>;
|
|
103
103
|
/**
|
|
104
|
-
*
|
|
104
|
+
* Enables / Disables the Echo effect, IMPORTANT! Only works with the correct Lavalink Plugin installed. (Optional: provide your Own Data)
|
|
105
105
|
* @param delays
|
|
106
106
|
* @param gains
|
|
107
107
|
* @returns
|
|
@@ -109,7 +109,7 @@ export declare class FilterManager {
|
|
|
109
109
|
toggleReverb: (delays?: number[], gains?: number[]) => Promise<boolean>;
|
|
110
110
|
};
|
|
111
111
|
/**
|
|
112
|
-
* Enables /
|
|
112
|
+
* Enables / Disables a Nightcore-like filter Effect. Disables/Overrides both: custom and Vaporwave Filter
|
|
113
113
|
* @param speed
|
|
114
114
|
* @param pitch
|
|
115
115
|
* @param rate
|
|
@@ -117,7 +117,7 @@ export declare class FilterManager {
|
|
|
117
117
|
*/
|
|
118
118
|
toggleNightcore(speed?: number, pitch?: number, rate?: number): Promise<boolean>;
|
|
119
119
|
/**
|
|
120
|
-
* Enables /
|
|
120
|
+
* Enables / Disables a Vaporwave-like filter Effect. Disables/Overrides both: custom and nightcore Filter
|
|
121
121
|
* @param speed
|
|
122
122
|
* @param pitch
|
|
123
123
|
* @param rate
|
|
@@ -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
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -84,7 +84,7 @@ export interface LavalinkPlayOptions extends BasePlayOptions {
|
|
|
84
84
|
export interface PlayOptions extends LavalinkPlayOptions {
|
|
85
85
|
/** Whether to not replace the track if a play payload is sent. */
|
|
86
86
|
noReplace?: boolean;
|
|
87
|
-
/**
|
|
87
|
+
/** Adds track on queue and skips to it */
|
|
88
88
|
clientTrack?: Track | UnresolvedTrack;
|
|
89
89
|
}
|
|
90
90
|
export interface Player {
|
|
@@ -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").
|
|
175
|
+
search(query: SearchQuery, requestUser: unknown): Promise<import("./Utils").SearchResult | import("./Utils").UnresolvedSearchResult>;
|
|
176
176
|
/**
|
|
177
177
|
* Pause the player
|
|
178
178
|
*/
|
|
@@ -195,7 +195,7 @@ export declare class Player {
|
|
|
195
195
|
* Skip the current song, or a specific amount of songs
|
|
196
196
|
* @param amount provide the index of the next track to skip to
|
|
197
197
|
*/
|
|
198
|
-
skip(skipTo?: number, throwError?: boolean):
|
|
198
|
+
skip(skipTo?: number, throwError?: boolean): any;
|
|
199
199
|
/**
|
|
200
200
|
* Clears the queue and stops playing. Does not destroy the Player and not leave the channel
|
|
201
201
|
* @returns
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lavalink-client",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
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": {
|