distube 4.0.0-dev.0 → 4.0.0-dev.3

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.
Files changed (121) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +593 -8
  3. package/dist/index.js +2360 -22
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +2300 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +79 -43
  8. package/dist/DisTube.d.ts +0 -521
  9. package/dist/DisTube.d.ts.map +0 -1
  10. package/dist/DisTube.js +0 -793
  11. package/dist/DisTube.js.map +0 -1
  12. package/dist/constant.d.ts +0 -124
  13. package/dist/constant.d.ts.map +0 -1
  14. package/dist/constant.js +0 -144
  15. package/dist/constant.js.map +0 -1
  16. package/dist/core/DisTubeBase.d.ts +0 -54
  17. package/dist/core/DisTubeBase.d.ts.map +0 -1
  18. package/dist/core/DisTubeBase.js +0 -75
  19. package/dist/core/DisTubeBase.js.map +0 -1
  20. package/dist/core/DisTubeHandler.d.ts +0 -93
  21. package/dist/core/DisTubeHandler.d.ts.map +0 -1
  22. package/dist/core/DisTubeHandler.js +0 -292
  23. package/dist/core/DisTubeHandler.js.map +0 -1
  24. package/dist/core/DisTubeOptions.d.ts +0 -23
  25. package/dist/core/DisTubeOptions.d.ts.map +0 -1
  26. package/dist/core/DisTubeOptions.js +0 -90
  27. package/dist/core/DisTubeOptions.js.map +0 -1
  28. package/dist/core/DisTubeStream.d.ts +0 -52
  29. package/dist/core/DisTubeStream.d.ts.map +0 -1
  30. package/dist/core/DisTubeStream.js +0 -108
  31. package/dist/core/DisTubeStream.js.map +0 -1
  32. package/dist/core/index.d.ts +0 -7
  33. package/dist/core/index.d.ts.map +0 -1
  34. package/dist/core/index.js +0 -19
  35. package/dist/core/index.js.map +0 -1
  36. package/dist/core/manager/BaseManager.d.ts +0 -22
  37. package/dist/core/manager/BaseManager.d.ts.map +0 -1
  38. package/dist/core/manager/BaseManager.js +0 -42
  39. package/dist/core/manager/BaseManager.js.map +0 -1
  40. package/dist/core/manager/QueueManager.d.ts +0 -33
  41. package/dist/core/manager/QueueManager.d.ts.map +0 -1
  42. package/dist/core/manager/QueueManager.js +0 -193
  43. package/dist/core/manager/QueueManager.js.map +0 -1
  44. package/dist/core/manager/index.d.ts +0 -3
  45. package/dist/core/manager/index.d.ts.map +0 -1
  46. package/dist/core/manager/index.js +0 -15
  47. package/dist/core/manager/index.js.map +0 -1
  48. package/dist/core/voice/DisTubeVoice.d.ts +0 -82
  49. package/dist/core/voice/DisTubeVoice.d.ts.map +0 -1
  50. package/dist/core/voice/DisTubeVoice.js +0 -250
  51. package/dist/core/voice/DisTubeVoice.js.map +0 -1
  52. package/dist/core/voice/DisTubeVoiceManager.d.ts +0 -41
  53. package/dist/core/voice/DisTubeVoiceManager.d.ts.map +0 -1
  54. package/dist/core/voice/DisTubeVoiceManager.js +0 -67
  55. package/dist/core/voice/DisTubeVoiceManager.js.map +0 -1
  56. package/dist/core/voice/index.d.ts +0 -3
  57. package/dist/core/voice/index.d.ts.map +0 -1
  58. package/dist/core/voice/index.js +0 -15
  59. package/dist/core/voice/index.js.map +0 -1
  60. package/dist/index.d.ts.map +0 -1
  61. package/dist/plugin/http.d.ts +0 -10
  62. package/dist/plugin/http.d.ts.map +0 -1
  63. package/dist/plugin/http.js +0 -18
  64. package/dist/plugin/http.js.map +0 -1
  65. package/dist/plugin/https.d.ts +0 -19
  66. package/dist/plugin/https.d.ts.map +0 -1
  67. package/dist/plugin/https.js +0 -47
  68. package/dist/plugin/https.js.map +0 -1
  69. package/dist/plugin/index.d.ts +0 -3
  70. package/dist/plugin/index.d.ts.map +0 -1
  71. package/dist/plugin/index.js +0 -15
  72. package/dist/plugin/index.js.map +0 -1
  73. package/dist/struct/CustomPlugin.d.ts +0 -51
  74. package/dist/struct/CustomPlugin.d.ts.map +0 -1
  75. package/dist/struct/CustomPlugin.js +0 -50
  76. package/dist/struct/CustomPlugin.js.map +0 -1
  77. package/dist/struct/DisTubeError.d.ts +0 -55
  78. package/dist/struct/DisTubeError.d.ts.map +0 -1
  79. package/dist/struct/DisTubeError.js +0 -64
  80. package/dist/struct/DisTubeError.js.map +0 -1
  81. package/dist/struct/ExtractorPlugin.d.ts +0 -45
  82. package/dist/struct/ExtractorPlugin.d.ts.map +0 -1
  83. package/dist/struct/ExtractorPlugin.js +0 -39
  84. package/dist/struct/ExtractorPlugin.js.map +0 -1
  85. package/dist/struct/Playlist.d.ts +0 -54
  86. package/dist/struct/Playlist.d.ts.map +0 -1
  87. package/dist/struct/Playlist.js +0 -131
  88. package/dist/struct/Playlist.js.map +0 -1
  89. package/dist/struct/Plugin.d.ts +0 -75
  90. package/dist/struct/Plugin.d.ts.map +0 -1
  91. package/dist/struct/Plugin.js +0 -99
  92. package/dist/struct/Plugin.js.map +0 -1
  93. package/dist/struct/Queue.d.ts +0 -216
  94. package/dist/struct/Queue.d.ts.map +0 -1
  95. package/dist/struct/Queue.js +0 -479
  96. package/dist/struct/Queue.js.map +0 -1
  97. package/dist/struct/SearchResult.d.ts +0 -27
  98. package/dist/struct/SearchResult.d.ts.map +0 -1
  99. package/dist/struct/SearchResult.js +0 -77
  100. package/dist/struct/SearchResult.js.map +0 -1
  101. package/dist/struct/Song.d.ts +0 -78
  102. package/dist/struct/Song.d.ts.map +0 -1
  103. package/dist/struct/Song.js +0 -259
  104. package/dist/struct/Song.js.map +0 -1
  105. package/dist/struct/TaskQueue.d.ts +0 -28
  106. package/dist/struct/TaskQueue.d.ts.map +0 -1
  107. package/dist/struct/TaskQueue.js +0 -64
  108. package/dist/struct/TaskQueue.js.map +0 -1
  109. package/dist/struct/index.d.ts +0 -10
  110. package/dist/struct/index.d.ts.map +0 -1
  111. package/dist/struct/index.js +0 -22
  112. package/dist/struct/index.js.map +0 -1
  113. package/dist/tsconfig.tsbuildinfo +0 -1
  114. package/dist/type.d.ts +0 -169
  115. package/dist/type.d.ts.map +0 -1
  116. package/dist/type.js +0 -3
  117. package/dist/type.js.map +0 -1
  118. package/dist/util.d.ts +0 -51
  119. package/dist/util.d.ts.map +0 -1
  120. package/dist/util.js +0 -225
  121. package/dist/util.js.map +0 -1
package/dist/DisTube.js DELETED
@@ -1,793 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.DisTube = exports.version = void 0;
7
- const ytpl_1 = __importDefault(require("@distube/ytpl"));
8
- const ytsr_1 = __importDefault(require("@distube/ytsr"));
9
- const util_1 = require("./util");
10
- const tiny_typed_emitter_1 = require("tiny-typed-emitter");
11
- const _1 = require(".");
12
- // Cannot be `import` as it's not under TS root dir
13
- // eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
14
- exports.version = require("../package.json").version;
15
- /**
16
- * DisTube class
17
- * @extends EventEmitter
18
- */
19
- class DisTube extends tiny_typed_emitter_1.TypedEmitter {
20
- /**
21
- * Create a new DisTube class.
22
- * @param {Discord.Client} client Discord.JS client
23
- * @param {DisTubeOptions} [otp] Custom DisTube options
24
- * @example
25
- * const Discord = require('discord.js'),
26
- * DisTube = require('distube'),
27
- * client = new Discord.Client();
28
- * // Create a new DisTube
29
- * const distube = new DisTube.default(client, { searchSongs: 10 });
30
- * // client.DisTube = distube // make it access easily
31
- * client.login("Your Discord Bot Token")
32
- */
33
- constructor(client, otp = {}) {
34
- super();
35
- this.setMaxListeners(1);
36
- if (!(0, _1.isClientInstance)(client))
37
- throw new _1.DisTubeError("INVALID_TYPE", "Discord.Client", client, "client");
38
- /**
39
- * Discord.JS client
40
- * @type {Discord.Client}
41
- */
42
- this.client = client;
43
- (0, util_1.checkIntents)(client.options);
44
- /**
45
- * DisTube options
46
- * @type {DisTubeOptions}
47
- */
48
- this.options = new _1.Options(otp);
49
- /**
50
- * Voice connections manager
51
- * @type {DisTubeVoiceManager}
52
- */
53
- this.voices = new _1.DisTubeVoiceManager(this);
54
- /**
55
- * DisTube's Handler
56
- * @type {DisTubeHandler}
57
- * @private
58
- */
59
- this.handler = new _1.DisTubeHandler(this);
60
- /**
61
- * Queues manager
62
- * @type {QueueManager}
63
- */
64
- this.queues = new _1.QueueManager(this);
65
- /**
66
- * DisTube filters
67
- * @type {Filters}
68
- */
69
- this.filters = { ..._1.defaultFilters, ...this.options.customFilters };
70
- // Default plugin
71
- this.options.plugins.push(new _1.HTTPPlugin(), new _1.HTTPSPlugin());
72
- this.options.plugins.map(p => p.init(this));
73
- /**
74
- * Extractor Plugins
75
- * @type {ExtractorPlugin[]}
76
- * @private
77
- */
78
- this.extractorPlugins = this.options.plugins.filter((p) => p.type === "extractor");
79
- /**
80
- * Custom Plugins
81
- * @type {CustomPlugin[]}
82
- * @private
83
- */
84
- this.customPlugins = this.options.plugins.filter((p) => p.type === "custom");
85
- }
86
- static get version() {
87
- return exports.version;
88
- }
89
- /**
90
- * DisTube version
91
- * @type {string}
92
- */
93
- get version() {
94
- return exports.version;
95
- }
96
- /**
97
- * Play / add a song or playlist from url. Search and play a song if it is not a valid url.
98
- *
99
- * @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
100
- * @param {string|Song|SearchResult|Playlist} song URL | Search string |
101
- * {@link Song} | {@link SearchResult} | {@link Playlist}
102
- * @param {Object} [options] Optional options
103
- * @param {boolean} [options.skip=false]
104
- * Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
105
- * If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
106
- * @param {number} [options.position=0] Position of the song/playlist to add to the queue,
107
- * <= 0 to add to the end of the queue.
108
- * @param {boolean} [options.unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
109
- * (after the playing song if exists)
110
- * @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
111
- * @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
112
- * @param {Discord.Message} [options.message] Called message (For built-in search events. If this is a {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy|falsy value}, it will play the first result instead)
113
- * @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
114
- * This is useful for identification purposes when the song/playlist is passed around in events.
115
- * See {@link Song#metadata} or {@link Playlist#metadata}
116
- * @example
117
- * client.on('message', (message) => {
118
- * if (!message.content.startsWith(config.prefix)) return;
119
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
120
- * const command = args.shift();
121
- * if (command == "play")
122
- * distube.play(message.member.voice?.channel, args.join(" "), {
123
- * member: message.member,
124
- * textChannel: message.channel,
125
- * message
126
- * });
127
- * });
128
- * @returns {Promise<void>}
129
- */
130
- async play(voiceChannel, song, options = {}) {
131
- if (!(0, _1.isSupportedVoiceChannel)(voiceChannel)) {
132
- throw new _1.DisTubeError("INVALID_TYPE", "BaseGuildVoiceChannel", voiceChannel, "voiceChannel");
133
- }
134
- if (!(0, util_1.isObject)(options))
135
- throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
136
- const { textChannel, member, skip, message, metadata } = {
137
- member: voiceChannel.guild.me ?? undefined,
138
- textChannel: options?.message?.channel,
139
- skip: false,
140
- ...options,
141
- };
142
- let position = Number(options.position);
143
- if (!position) {
144
- if (skip && position !== 0)
145
- position = 1;
146
- else
147
- position = 0;
148
- }
149
- if (message && !(0, _1.isMessageInstance)(message)) {
150
- throw new _1.DisTubeError("INVALID_TYPE", ["Discord.Message", "a falsy value"], message, "options.message");
151
- }
152
- if (textChannel && !(0, _1.isTextChannelInstance)(textChannel)) {
153
- throw new _1.DisTubeError("INVALID_TYPE", "Discord.GuildTextBasedChannel", textChannel, "options.textChannel");
154
- }
155
- if (member && !(0, _1.isMemberInstance)(member)) {
156
- throw new _1.DisTubeError("INVALID_TYPE", "Discord.GuildMember", member, "options.member");
157
- }
158
- try {
159
- if (typeof song === "string") {
160
- for (const plugin of this.customPlugins) {
161
- if (await plugin.validate(song)) {
162
- return plugin.play(voiceChannel, song, options);
163
- }
164
- }
165
- }
166
- let queue = this.getQueue(voiceChannel);
167
- const queuing = !!queue && !queue.taskQueue.hasResolveTask;
168
- if (queuing)
169
- await queue?.taskQueue.queuing(true);
170
- try {
171
- if (song instanceof _1.SearchResult && song.type === "playlist")
172
- song = song.url;
173
- if (typeof song === "string" && ytpl_1.default.validateID(song)) {
174
- song = await this.handler.resolvePlaylist(song, { member, metadata });
175
- }
176
- if (typeof song === "string" && !(0, util_1.isURL)(song)) {
177
- if (!message) {
178
- song = (await this.search(song, { limit: 1 }))[0];
179
- }
180
- else {
181
- const result = await this.handler.searchSong(message, song);
182
- if (!result)
183
- return;
184
- song = result;
185
- }
186
- }
187
- song = await this.handler.resolveSong(song, { member, metadata });
188
- if (song instanceof _1.Playlist) {
189
- await this.handler.handlePlaylist(voiceChannel, song, { textChannel, skip, position });
190
- }
191
- else if (!this.options.nsfw && song.age_restricted && !textChannel?.nsfw) {
192
- throw new _1.DisTubeError("NON_NSFW");
193
- }
194
- else {
195
- queue = this.getQueue(voiceChannel);
196
- if (queue) {
197
- queue.addToQueue(song, position);
198
- if (skip)
199
- queue.skip();
200
- else
201
- this.emit("addSong", queue, song);
202
- }
203
- else {
204
- const newQueue = await this.queues.create(voiceChannel, song, textChannel);
205
- if (newQueue instanceof _1.Queue) {
206
- if (this.options.emitAddSongWhenCreatingQueue)
207
- this.emit("addSong", newQueue, song);
208
- this.emit("playSong", newQueue, song);
209
- }
210
- }
211
- }
212
- }
213
- finally {
214
- if (queuing)
215
- queue?.taskQueue.resolve();
216
- }
217
- }
218
- catch (e) {
219
- if (!(e instanceof _1.DisTubeError)) {
220
- try {
221
- e.name = "PlayError";
222
- e.message = `${song?.url || song}\n${e.message}`;
223
- }
224
- catch { }
225
- }
226
- this.emitError(e, textChannel);
227
- }
228
- }
229
- /**
230
- * Create a custom playlist
231
- * @returns {Promise<Playlist>}
232
- * @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
233
- * @param {Object} [options] Optional options
234
- * @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
235
- * @param {Object} [options.properties] Additional properties such as `name`
236
- * @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
237
- * @param {*} [options.metadata] Metadata
238
- * @example
239
- * const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
240
- * const playlist = await distube.createCustomPlaylist(songs, {
241
- * member: message.member,
242
- * properties: { name: "My playlist name" },
243
- * parallel: true
244
- * });
245
- * distube.play(voiceChannel, playlist, { ... });
246
- */
247
- async createCustomPlaylist(songs, options = {}) {
248
- const { member, properties, parallel, metadata } = { parallel: true, ...options };
249
- if (!Array.isArray(songs))
250
- throw new _1.DisTubeError("INVALID_TYPE", "Array", songs, "songs");
251
- if (!songs.length)
252
- throw new _1.DisTubeError("EMPTY_ARRAY", "songs");
253
- const filteredSongs = songs.filter(song => song instanceof _1.Song || (song instanceof _1.SearchResult && song.type === "video") || (0, util_1.isURL)(song));
254
- if (!filteredSongs.length)
255
- throw new _1.DisTubeError("NO_VALID_SONG");
256
- if (member && !(0, _1.isMemberInstance)(member)) {
257
- throw new _1.DisTubeError("INVALID_TYPE", "Discord.Member", member, "options.member");
258
- }
259
- if (!filteredSongs.length)
260
- throw new _1.DisTubeError("NO_VALID_SONG");
261
- let resolvedSongs;
262
- if (parallel) {
263
- const promises = filteredSongs.map((song) => this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
264
- resolvedSongs = (await Promise.all(promises)).filter((s) => !!s);
265
- }
266
- else {
267
- const resolved = [];
268
- for (const song of filteredSongs) {
269
- resolved.push(await this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
270
- }
271
- resolvedSongs = resolved.filter((s) => !!s);
272
- }
273
- return new _1.Playlist(resolvedSongs, { member, properties, metadata });
274
- }
275
- /**
276
- * Search for a song. You can customize how user answers instead of send a number.
277
- * Then use {@link DisTube#play} to play it.
278
- *
279
- * @param {string} string The string search for
280
- * @param {Object} options Search options
281
- * @param {number} [options.limit=10] Limit the results
282
- * @param {'video'|'playlist'} [options.type='video'] Type of results (`video` or `playlist`).
283
- * @param {boolean} [options.safeSearch=false] Whether or not use safe search (YouTube restricted mode)
284
- * @throws {Error}
285
- * @returns {Promise<Array<SearchResult>>} Array of results
286
- */
287
- async search(string, options = {}) {
288
- const opts = { type: "video", limit: 10, safeSearch: false, ...options };
289
- if (typeof opts.type !== "string" || !["video", "playlist"].includes(opts.type)) {
290
- throw new _1.DisTubeError("INVALID_TYPE", ["video", "playlist"], opts.type, "options.type");
291
- }
292
- if (typeof opts.limit !== "number")
293
- throw new _1.DisTubeError("INVALID_TYPE", "number", opts.limit, "options.limit");
294
- if (opts.limit < 1)
295
- throw new _1.DisTubeError("NUMBER_COMPARE", "option.limit", "bigger or equal to", 1);
296
- if (typeof opts.safeSearch !== "boolean") {
297
- throw new _1.DisTubeError("INVALID_TYPE", "boolean", opts.safeSearch, "options.safeSearch");
298
- }
299
- try {
300
- const search = await (0, ytsr_1.default)(string, opts);
301
- const results = search.items.map(i => new _1.SearchResult(i));
302
- if (results.length === 0)
303
- throw new _1.DisTubeError("NO_RESULT");
304
- return results;
305
- }
306
- catch (e) {
307
- if (options.retried)
308
- throw e;
309
- options.retried = true;
310
- return this.search(string, options);
311
- }
312
- }
313
- /**
314
- * Get the guild queue
315
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
316
- * @returns {Queue?}
317
- * @throws {Error}
318
- * @example
319
- * client.on('message', (message) => {
320
- * if (!message.content.startsWith(config.prefix)) return;
321
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
322
- * const command = args.shift();
323
- * if (command == "queue") {
324
- * const queue = distube.getQueue(message);
325
- * message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
326
- * `**${id+1}**. [${song.name}](${song.url}) - \`${song.formattedDuration}\``
327
- * ).join("\n"));
328
- * }
329
- * });
330
- */
331
- getQueue(queue) {
332
- return this.queues.get(queue);
333
- }
334
- /**
335
- * Pause the guild stream
336
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
337
- * @returns {Queue} The guild queue
338
- * @throws {Error}
339
- */
340
- pause(queue) {
341
- const q = this.getQueue(queue);
342
- if (!q)
343
- throw new _1.DisTubeError("NO_QUEUE");
344
- return q.pause();
345
- }
346
- /**
347
- * Resume the guild stream
348
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
349
- * @returns {Queue} The guild queue
350
- * @throws {Error}
351
- */
352
- resume(queue) {
353
- const q = this.getQueue(queue);
354
- if (!q)
355
- throw new _1.DisTubeError("NO_QUEUE");
356
- return q.resume();
357
- }
358
- /**
359
- * Stop the guild stream
360
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
361
- * @returns {Promise<void>}
362
- * @throws {Error}
363
- * @example
364
- * client.on('message', (message) => {
365
- * if (!message.content.startsWith(config.prefix)) return;
366
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
367
- * const command = args.shift();
368
- * if (command == "stop") {
369
- * distube.stop(message);
370
- * message.channel.send("Stopped the queue!");
371
- * }
372
- * });
373
- */
374
- stop(queue) {
375
- const q = this.getQueue(queue);
376
- if (!q)
377
- throw new _1.DisTubeError("NO_QUEUE");
378
- return q.stop();
379
- }
380
- /**
381
- * Set the guild stream's volume
382
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
383
- * @param {number} percent The percentage of volume you want to set
384
- * @returns {Queue} The guild queue
385
- * @throws {Error}
386
- * @example
387
- * client.on('message', (message) => {
388
- * if (!message.content.startsWith(config.prefix)) return;
389
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
390
- * const command = args.shift();
391
- * if (command == "volume")
392
- * distube.setVolume(message, Number(args[0]));
393
- * });
394
- */
395
- setVolume(queue, percent) {
396
- const q = this.getQueue(queue);
397
- if (!q)
398
- throw new _1.DisTubeError("NO_QUEUE");
399
- return q.setVolume(percent);
400
- }
401
- /**
402
- * Skip the playing song if there is a next song in the queue.
403
- * <info>If {@link Queue#autoplay} is `true` and there is no up next song,
404
- * DisTube will add and play a related song.</info>
405
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
406
- * @returns {Promise<Song>} The new Song will be played
407
- * @throws {Error}
408
- * @example
409
- * client.on('message', (message) => {
410
- * if (!message.content.startsWith(config.prefix)) return;
411
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
412
- * const command = args.shift();
413
- * if (command == "skip")
414
- * distube.skip(message);
415
- * });
416
- */
417
- skip(queue) {
418
- const q = this.getQueue(queue);
419
- if (!q)
420
- throw new _1.DisTubeError("NO_QUEUE");
421
- return q.skip();
422
- }
423
- /**
424
- * Play the previous song
425
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
426
- * @returns {Promise<Song>} The new Song will be played
427
- * @throws {Error}
428
- * @example
429
- * client.on('message', (message) => {
430
- * if (!message.content.startsWith(config.prefix)) return;
431
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
432
- * const command = args.shift();
433
- * if (command == "previous")
434
- * distube.previous(message);
435
- * });
436
- */
437
- previous(queue) {
438
- const q = this.getQueue(queue);
439
- if (!q)
440
- throw new _1.DisTubeError("NO_QUEUE");
441
- return q.previous();
442
- }
443
- /**
444
- * Shuffle the guild queue songs
445
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
446
- * @returns {Promise<Queue>} The guild queue
447
- * @example
448
- * client.on('message', (message) => {
449
- * if (!message.content.startsWith(config.prefix)) return;
450
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
451
- * const command = args.shift();
452
- * if (command == "shuffle")
453
- * distube.shuffle(message);
454
- * });
455
- */
456
- shuffle(queue) {
457
- const q = this.getQueue(queue);
458
- if (!q)
459
- throw new _1.DisTubeError("NO_QUEUE");
460
- return q.shuffle();
461
- }
462
- /**
463
- * Jump to the song number in the queue.
464
- * The next one is 1, 2,...
465
- * The previous one is -1, -2,...
466
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
467
- * @param {number} num The song number to play
468
- * @returns {Promise<Queue>} The guild queue
469
- * @throws {Error} if `num` is invalid number (0 < num < {@link Queue#songs}.length)
470
- * @example
471
- * client.on('message', (message) => {
472
- * if (!message.content.startsWith(config.prefix)) return;
473
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
474
- * const command = args.shift();
475
- * if (command == "jump")
476
- * distube.jump(message, parseInt(args[0]))
477
- * .catch(err => message.channel.send("Invalid song number."));
478
- * });
479
- */
480
- jump(queue, num) {
481
- const q = this.getQueue(queue);
482
- if (!q)
483
- throw new _1.DisTubeError("NO_QUEUE");
484
- return q.jump(num);
485
- }
486
- /**
487
- * Set the repeat mode of the guild queue.\
488
- * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`
489
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
490
- * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)
491
- * @returns {RepeatMode} The new repeat mode
492
- * @example
493
- * client.on('message', (message) => {
494
- * if (!message.content.startsWith(config.prefix)) return;
495
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
496
- * const command = args.shift();
497
- * if (command == "repeat") {
498
- * let mode = distube.setRepeatMode(message, parseInt(args[0]));
499
- * mode = mode ? mode == 2 ? "Repeat queue" : "Repeat song" : "Off";
500
- * message.channel.send("Set repeat mode to `" + mode + "`");
501
- * }
502
- * });
503
- * @example
504
- * const { RepeatMode } = require("distube");
505
- * let mode;
506
- * switch(distube.setRepeatMode(message, parseInt(args[0]))) {
507
- * case RepeatMode.DISABLED:
508
- * mode = "Off";
509
- * break;
510
- * case RepeatMode.SONG:
511
- * mode = "Repeat a song";
512
- * break;
513
- * case RepeatMode.QUEUE:
514
- * mode = "Repeat all queue";
515
- * break;
516
- * }
517
- * message.channel.send("Set repeat mode to `" + mode + "`");
518
- */
519
- setRepeatMode(queue, mode) {
520
- const q = this.getQueue(queue);
521
- if (!q)
522
- throw new _1.DisTubeError("NO_QUEUE");
523
- return q.setRepeatMode(mode);
524
- }
525
- /**
526
- * Toggle autoplay mode
527
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
528
- * @returns {boolean} Autoplay mode state
529
- * @throws {Error}
530
- * @example
531
- * client.on('message', (message) => {
532
- * if (!message.content.startsWith(config.prefix)) return;
533
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
534
- * const command = args.shift();
535
- * if (command == "autoplay") {
536
- * const mode = distube.toggleAutoplay(message);
537
- * message.channel.send("Set autoplay mode to `" + (mode ? "On" : "Off") + "`");
538
- * }
539
- * });
540
- */
541
- toggleAutoplay(queue) {
542
- const q = this.getQueue(queue);
543
- if (!q)
544
- throw new _1.DisTubeError("NO_QUEUE");
545
- q.autoplay = !q.autoplay;
546
- return q.autoplay;
547
- }
548
- /**
549
- * Add related song to the queue
550
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
551
- * @returns {Promise<Song>} The guild queue
552
- */
553
- addRelatedSong(queue) {
554
- const q = this.getQueue(queue);
555
- if (!q)
556
- throw new _1.DisTubeError("NO_QUEUE");
557
- return q.addRelatedSong();
558
- }
559
- /**
560
- * Enable or disable filter(s) of the queue.
561
- * Available filters: {@link Filters}
562
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
563
- * @param {string|false} filter A filter name, `false` to clear all the filters
564
- * @param {boolean} [force=false] Force enable the input filter(s) even if it's enabled
565
- * @returns {Array<string>} Enabled filters.
566
- * @example
567
- * client.on('message', (message) => {
568
- * if (!message.content.startsWith(config.prefix)) return;
569
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
570
- * const command = args.shift();
571
- * if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
572
- * const filter = distube.setFilter(message, command);
573
- * message.channel.send("Current queue filter: " + (filter.join(", ") || "Off"));
574
- * }
575
- * });
576
- */
577
- setFilter(queue, filter, force = false) {
578
- const q = this.getQueue(queue);
579
- if (!q)
580
- throw new _1.DisTubeError("NO_QUEUE");
581
- return q.setFilter(filter, force);
582
- }
583
- /**
584
- * Set the playing time to another position
585
- * @param {GuildIdResolvable} queue The type can be resolved to give a {@link Queue}
586
- * @param {number} time Time in seconds
587
- * @returns {Queue} Seeked queue
588
- * @example
589
- * client.on('message', message => {
590
- * if (!message.content.startsWith(config.prefix)) return;
591
- * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
592
- * const command = args.shift();
593
- * if (command = 'seek')
594
- * distube.seek(message, Number(args[0]));
595
- * });
596
- */
597
- seek(queue, time) {
598
- const q = this.getQueue(queue);
599
- if (!q)
600
- throw new _1.DisTubeError("NO_QUEUE");
601
- return q.seek(time);
602
- }
603
- /* eslint-disable no-console */
604
- /**
605
- * Emit error event
606
- * @param {Error} error error
607
- * @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
608
- * @private
609
- */
610
- emitError(error, channel) {
611
- if (!channel || !(0, _1.isTextChannelInstance)(channel)) {
612
- console.error(error);
613
- console.warn("This is logged because <Queue>.textChannel is undefined");
614
- }
615
- else if (this.listeners("error").length) {
616
- this.emit("error", channel, error);
617
- }
618
- else {
619
- console.error(error);
620
- console.warn("Unhandled 'error' event.");
621
- console.warn("See: https://distube.js.org/#/docs/DisTube/stable/class/DisTube?scrollTo=e-error and https://nodejs.org/api/events.html#events_error_events");
622
- }
623
- }
624
- }
625
- exports.DisTube = DisTube;
626
- exports.default = DisTube;
627
- /**
628
- * Emitted after DisTube add a new playlist to the playing {@link Queue}.
629
- *
630
- * @event DisTube#addList
631
- * @param {Queue} queue The guild queue
632
- * @param {Playlist} playlist Playlist info
633
- * @example
634
- * distube.on("addList", (queue, playlist) => queue.textChannel.send(
635
- * `Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to the queue!`
636
- * ));
637
- */
638
- /**
639
- * Emitted after DisTube add a new song to the playing {@link Queue}.
640
- *
641
- * @event DisTube#addSong
642
- * @param {Queue} queue The guild queue
643
- * @param {Song} song Added song
644
- * @example
645
- * distube.on("addSong", (queue, song) => queue.textChannel.send(
646
- * `Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}.`
647
- * ));
648
- */
649
- /**
650
- * Emitted when there is no user in the voice channel,
651
- * {@link DisTubeOptions}.leaveOnEmpty is `true` and there is a playing queue.
652
- *
653
- * If there is no playing queue (stopped and {@link DisTubeOptions}.leaveOnStop is `false`),
654
- * it will leave the channel without emitting this event.
655
- * @event DisTube#empty
656
- * @param {Queue} queue The guild queue
657
- * @example
658
- * distube.on("empty", queue => queue.textChannel.send("Channel is empty. Leaving the channel"))
659
- */
660
- /**
661
- * Emitted when DisTube encounters an error.
662
- *
663
- * @event DisTube#error
664
- * @param {Discord.BaseGuildTextChannel} channel Text channel where the error is encountered.
665
- * @param {Error} error The error encountered
666
- * @example
667
- * distube.on("error", (channel, error) => channel.send(
668
- * "An error encountered: " + error
669
- * ));
670
- */
671
- /**
672
- * Emitted when there is no more song in the queue and {@link Queue#autoplay} is `false`.
673
- * DisTube will leave voice channel if {@link DisTubeOptions}.leaveOnFinish is `true`.
674
- *
675
- * @event DisTube#finish
676
- * @param {Queue} queue The guild queue
677
- * @example
678
- * distube.on("finish", queue => queue.textChannel.send("No more song in queue"));
679
- */
680
- /**
681
- * Emitted when DisTube initialize a queue to change queue default properties.
682
- *
683
- * @event DisTube#initQueue
684
- * @param {Queue} queue The guild queue
685
- * @example
686
- * distube.on("initQueue", queue => {
687
- * queue.autoplay = false;
688
- * queue.volume = 100;
689
- * });
690
- */
691
- /**
692
- * Emitted when {@link Queue#autoplay} is `true`, {@link Queue#songs} is empty,
693
- * and DisTube cannot find related songs to play.
694
- *
695
- * @event DisTube#noRelated
696
- * @param {Queue} queue The guild queue
697
- * @example
698
- * distube.on("noRelated", queue => queue.textChannel.send("Can't find related video to play."));
699
- */
700
- /**
701
- * Emitted when DisTube play a song.
702
- *
703
- * If {@link DisTubeOptions}.emitNewSongOnly is `true`,
704
- * this event is not emitted when looping a song or next song is the previous one.
705
- *
706
- * @event DisTube#playSong
707
- * @param {Queue} queue The guild queue
708
- * @param {Song} song Playing song
709
- * @example
710
- * distube.on("playSong", (queue, song) => queue.textChannel.send(
711
- * `Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}`
712
- * ));
713
- */
714
- /**
715
- * Emitted when DisTube cannot find any results for the query.
716
- *
717
- * @event DisTube#searchNoResult
718
- * @param {Discord.Message} message The user message called play method
719
- * @param {string} query The search query
720
- * @example
721
- * distube.on("searchNoResult", (message, query) => message.channel.send(`No result found for ${query}!`));
722
- */
723
- /**
724
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
725
- * and song param of {@link DisTube#play} is invalid url.
726
- * DisTube will wait for user's next message to choose a song manually.
727
- * <info>{@link https://support.google.com/youtube/answer/7354993|Safe search} is enabled
728
- * if {@link DisTubeOptions}.nsfw is disabled and the message's channel is not a nsfw channel.</info>
729
- *
730
- * @event DisTube#searchResult
731
- * @param {Discord.Message} message The user message called play method
732
- * @param {Array<SearchResult>} results Searched results
733
- * @param {string} query The search query
734
- * @example
735
- * // DisTubeOptions.searchSongs > 0
736
- * distube.on("searchResult", (message, results) => {
737
- * message.channel.send(`**Choose an option from below**\n${
738
- * results.map((song, i) => `**${i + 1}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")
739
- * }\n*Enter anything else or wait 60 seconds to cancel*`);
740
- * });
741
- */
742
- /**
743
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
744
- * and the search canceled due to {@link DisTubeOptions|DisTubeOptions.searchTimeout}.
745
- *
746
- * @event DisTube#searchCancel
747
- * @param {Discord.Message} message The user message called play method
748
- * @param {string} query The search query
749
- * @example
750
- * // DisTubeOptions.searchSongs > 0
751
- * distube.on("searchCancel", (message) => message.channel.send(`Searching canceled`));
752
- */
753
- /**
754
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
755
- * and the search canceled due to user's next message is not a number or out of results range.
756
- *
757
- * @event DisTube#searchInvalidAnswer
758
- * @param {Discord.Message} message The user message called play method
759
- * @param {Discord.Message} answer The answered message of user
760
- * @param {string} query The search query
761
- * @example
762
- * // DisTubeOptions.searchSongs > 0
763
- * distube.on("searchInvalidAnswer", (message) => message.channel.send(`You answered an invalid number!`));
764
- */
765
- /**
766
- * Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
767
- * and after the user chose a search result to play.
768
- *
769
- * @event DisTube#searchDone
770
- * @param {Discord.Message} message The user message called play method
771
- * @param {Discord.Message} answer The answered message of user
772
- * @param {string} query The search query
773
- */
774
- /**
775
- * Emitted when the bot is disconnected to a voice channel.
776
- *
777
- * @event DisTube#disconnect
778
- * @param {Queue} queue The guild queue
779
- */
780
- /**
781
- * Emitted when a {@link Queue} is deleted with any reasons.
782
- *
783
- * @event DisTube#deleteQueue
784
- * @param {Queue} queue The guild queue
785
- */
786
- /**
787
- * Emitted when DisTube finished a song.
788
- *
789
- * @event DisTube#finishSong
790
- * @param {Queue} queue The guild queue
791
- * @param {Song} song Finished song
792
- */
793
- //# sourceMappingURL=DisTube.js.map