distube 4.0.6 → 4.1.0

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import ytdl from '@distube/ytdl-core';
1
+ import ytdl, { Cookie } from '@distube/ytdl-core';
2
2
  import * as discord_js from 'discord.js';
3
3
  import { GuildTextBasedChannel, Message, Snowflake, VoiceBasedChannel, VoiceState, Guild, GuildMember, Interaction, Client, Collection, ClientOptions } from 'discord.js';
4
4
  import ytpl from '@distube/ytpl';
@@ -35,13 +35,73 @@ type DisTubeEvents = {
35
35
  type TypedDisTubeEvents = {
36
36
  [K in keyof DisTubeEvents]: (...args: DisTubeEvents[K]) => Awaitable;
37
37
  };
38
+ /**
39
+ * An FFmpeg audio filter object
40
+ * ```
41
+ * {
42
+ * name: "bassboost",
43
+ * value: "bass=g=10"
44
+ * }
45
+ * ```
46
+ * @typedef {Object} Filter
47
+ * @prop {string} name Name of the filter
48
+ * @prop {string} value FFmpeg audio filter(s)
49
+ */
38
50
  interface Filter {
39
51
  name: string;
40
52
  value: string;
41
53
  }
54
+ /**
55
+ * Data that resolves to give an FFmpeg audio filter. This can be:
56
+ * - A name of a default filters or custom filters (`string`)
57
+ * - A {@link Filter} object
58
+ * @typedef {string|Filter} FilterResolvable
59
+ * @see {@link defaultFilters}
60
+ * @see {@link DisTubeOptions|DisTubeOptions.customFilters}
61
+ */
42
62
  type FilterResolvable = string | Filter;
63
+ /**
64
+ * FFmpeg Filters
65
+ * ```
66
+ * {
67
+ * "Filter Name": "Filter Value",
68
+ * "bassboost": "bass=g=10"
69
+ * }
70
+ * ```
71
+ * @typedef {Object.<string, string>} Filters
72
+ * @see {@link defaultFilters}
73
+ */
43
74
  type Filters = Record<string, string>;
44
- interface DisTubeOptions {
75
+ /**
76
+ * DisTube options.
77
+ * @typedef {Object} DisTubeOptions
78
+ * @prop {Array<CustomPlugin|ExtractorPlugin>} [plugins] DisTube plugins.
79
+ * @prop {boolean} [emitNewSongOnly=false] Whether or not emitting {@link DisTube#event:playSong} event
80
+ * when looping a song or next song is the same as the previous one
81
+ * @prop {boolean} [leaveOnEmpty=true] Whether or not leaving voice channel
82
+ * if the voice channel is empty after {@link DisTubeOptions}.emptyCooldown seconds.
83
+ * @prop {boolean} [leaveOnFinish=false] Whether or not leaving voice channel when the queue ends.
84
+ * @prop {boolean} [leaveOnStop=true] Whether or not leaving voice channel after using {@link DisTube#stop} function.
85
+ * @prop {boolean} [savePreviousSongs=true] Whether or not saving the previous songs of the queue
86
+ * and enable {@link DisTube#previous} method
87
+ * @prop {number} [searchSongs=0] Limit of search results emits in {@link DisTube#event:searchResult} event
88
+ * when {@link DisTube#play} method executed. If `searchSongs <= 1`, play the first result
89
+ * @prop {Cookie[]|string} [youtubeCookie] YouTube cookies. Guide: {@link https://distube.js.org/#/docs/DisTube/main/general/cookie YouTube Cookies}
90
+ * @prop {Filters} [customFilters] Override {@link defaultFilters} or add more ffmpeg filters.
91
+ * @prop {ytdl.getInfoOptions} [ytdlOptions] `ytdl-core` get info options
92
+ * @prop {number} [searchCooldown=60] Built-in search cooldown in seconds (When searchSongs is bigger than 0)
93
+ * @prop {number} [emptyCooldown=60] Built-in leave on empty cooldown in seconds (When leaveOnEmpty is true)
94
+ * @prop {boolean} [nsfw=false] Whether or not playing age-restricted content
95
+ * and disabling safe search in non-NSFW channel.
96
+ * @prop {boolean} [emitAddListWhenCreatingQueue=true] Whether or not emitting `addList` event when creating a new Queue
97
+ * @prop {boolean} [emitAddSongWhenCreatingQueue=true] Whether or not emitting `addSong` event when creating a new Queue
98
+ * @prop {boolean} [joinNewVoiceChannel=true] Whether or not joining the new voice channel
99
+ * when using {@link DisTube#play} method
100
+ * @prop {StreamType} [streamType=StreamType.OPUS] Decide the {@link DisTubeStream#type} will be used
101
+ * (Not the same as {@link DisTubeStream#type})
102
+ * @prop {boolean} [directLink=true] Whether or not playing a song with direct link
103
+ */
104
+ type DisTubeOptions = {
45
105
  plugins?: (CustomPlugin | ExtractorPlugin)[];
46
106
  emitNewSongOnly?: boolean;
47
107
  leaveOnFinish?: boolean;
@@ -51,8 +111,7 @@ interface DisTubeOptions {
51
111
  savePreviousSongs?: boolean;
52
112
  searchSongs?: number;
53
113
  searchCooldown?: number;
54
- youtubeCookie?: string;
55
- youtubeIdentityToken?: string;
114
+ youtubeCookie?: Cookie[] | string;
56
115
  customFilters?: Filters;
57
116
  ytdlOptions?: ytdl.downloadOptions;
58
117
  nsfw?: boolean;
@@ -61,7 +120,33 @@ interface DisTubeOptions {
61
120
  joinNewVoiceChannel?: boolean;
62
121
  streamType?: StreamType;
63
122
  directLink?: boolean;
64
- }
123
+ };
124
+ /**
125
+ * Data that can be resolved to give a guild id string. This can be:
126
+ * - A guild id string | a guild {@link https://discord.js.org/#/docs/main/stable/class/Snowflake|Snowflake}
127
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/Guild|Guild}
128
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/Message|Message}
129
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/BaseGuildVoiceChannel|BaseGuildVoiceChannel}
130
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/BaseGuildTextChannel|BaseGuildTextChannel}
131
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/VoiceState|VoiceState}
132
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/GuildMember|GuildMember}
133
+ * - A {@link https://discord.js.org/#/docs/main/stable/class/Interaction|Interaction}
134
+ * - A {@link DisTubeVoice}
135
+ * - A {@link Queue}
136
+ * @typedef {
137
+ * Discord.Snowflake|
138
+ * Discord.Guild|
139
+ * Discord.Message|
140
+ * Discord.BaseGuildVoiceChannel|
141
+ * Discord.BaseGuildTextChannel|
142
+ * Discord.VoiceState|
143
+ * Discord.GuildMember|
144
+ * Discord.Interaction|
145
+ * DisTubeVoice|
146
+ * Queue|
147
+ * string
148
+ * } GuildIdResolvable
149
+ */
65
150
  type GuildIdResolvable = Queue | DisTubeVoice | Snowflake | Message | GuildTextBasedChannel | VoiceBasedChannel | VoiceState | Guild | GuildMember | Interaction | string;
66
151
  interface OtherSongInfo {
67
152
  src: string;
@@ -104,48 +189,132 @@ interface PlaylistInfo {
104
189
  name?: string;
105
190
  url?: string;
106
191
  thumbnail?: string;
192
+ /** @deprecated */
107
193
  title?: string;
194
+ /** @deprecated */
108
195
  webpage_url?: string;
109
196
  }
110
197
  type RelatedSong = Omit<Song, "related">;
198
+ /**
199
+ * @typedef {Object} PlayHandlerOptions
200
+ * @prop {Discord.BaseGuildTextChannel} [options.textChannel] The default text channel of the queue
201
+ * @prop {boolean} [options.skip=false] Skip the playing song (if exists) and play the added playlist instantly
202
+ * @prop {number} [options.position=0] Position of the song/playlist to add to the queue,
203
+ * <= 0 to add to the end of the queue.
204
+ */
111
205
  type PlayHandlerOptions = {
112
206
  skip?: boolean;
113
207
  position?: number;
114
208
  textChannel?: GuildTextBasedChannel;
115
209
  };
210
+ /**
211
+ * @typedef {Object} PlayOptions
212
+ * @prop {Discord.GuildMember} [member] Requested user (default is your bot)
213
+ * @prop {Discord.BaseGuildTextChannel} [textChannel] Default {@link Queue#textChannel}
214
+ * @prop {boolean} [skip=false]
215
+ * Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
216
+ * If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
217
+ * @prop {number} [position=0] Position of the song/playlist to add to the queue,
218
+ * <= 0 to add to the end of the queue.
219
+ * @prop {Discord.Message} [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)
220
+ * @prop {*} [metadata] Optional metadata that can be attached to the song/playlist will be played,
221
+ * This is useful for identification purposes when the song/playlist is passed around in events.
222
+ * See {@link Song#metadata} or {@link Playlist#metadata}
223
+ */
116
224
  interface PlayOptions extends PlayHandlerOptions, ResolveOptions<any> {
117
225
  message?: Message;
118
226
  }
227
+ /**
228
+ * @typedef {Object} ResolveOptions
229
+ * @prop {Discord.GuildMember} [member] Requested user
230
+ * @prop {*} [metadata] Metadata
231
+ */
119
232
  interface ResolveOptions<T = unknown> {
120
233
  member?: GuildMember;
121
234
  metadata?: T;
122
235
  }
236
+ /**
237
+ * @typedef {ResolveOptions} ResolvePlaylistOptions
238
+ * @prop {string} [source] Source of the playlist
239
+ */
123
240
  interface ResolvePlaylistOptions<T = unknown> extends ResolveOptions<T> {
124
241
  source?: string;
125
242
  }
243
+ /**
244
+ * @typedef {Object} CustomPlaylistOptions
245
+ * @prop {Discord.GuildMember} [member] A guild member creating the playlist
246
+ * @prop {Object} [properties] Additional properties such as `name`
247
+ * @prop {boolean} [parallel=true] Whether or not fetch the songs in parallel
248
+ * @prop {*} [metadata] Metadata
249
+ */
126
250
  interface CustomPlaylistOptions {
127
251
  member?: GuildMember;
128
252
  properties?: Record<string, any>;
129
253
  parallel?: boolean;
130
254
  metadata?: any;
131
255
  }
256
+ /**
257
+ * The repeat mode of a {@link Queue}
258
+ * * `DISABLED` = 0
259
+ * * `SONG` = 1
260
+ * * `QUEUE` = 2
261
+ * @typedef {number} RepeatMode
262
+ */
132
263
  declare enum RepeatMode {
133
264
  DISABLED = 0,
134
265
  SONG = 1,
135
266
  QUEUE = 2
136
267
  }
268
+ /**
269
+ * All available plugin types:
270
+ * * `CUSTOM` = `"custom"`: {@link CustomPlugin}
271
+ * * `EXTRACTOR` = `"extractor"`: {@link ExtractorPlugin}
272
+ * @typedef {"custom"|"extractor"} PluginType
273
+ */
137
274
  declare enum PluginType {
138
275
  CUSTOM = "custom",
139
276
  EXTRACTOR = "extractor"
140
277
  }
278
+ /**
279
+ * Search result types:
280
+ * * `VIDEO` = `"video"`
281
+ * * `PLAYLIST` = `"playlist"`
282
+ * @typedef {"video"|"playlist"} SearchResultType
283
+ */
141
284
  declare enum SearchResultType {
142
285
  VIDEO = "video",
143
286
  PLAYLIST = "playlist"
144
287
  }
288
+ /**
289
+ * Stream types:
290
+ * * `OPUS` = `0` (Better quality, use more resources - **Recommended**)
291
+ * * `RAW` = `1` (Better performance, use less resources)
292
+ * @typedef {number} StreamType
293
+ * @type {StreamType}
294
+ */
145
295
  declare enum StreamType {
146
296
  OPUS = 0,
147
297
  RAW = 1
148
298
  }
299
+ /**
300
+ * @typedef {Object} Events
301
+ * @prop {string} ERROR error
302
+ * @prop {string} ADD_LIST addList
303
+ * @prop {string} ADD_SONG addSong
304
+ * @prop {string} PLAY_SONG playSong
305
+ * @prop {string} FINISH_SONG finishSong
306
+ * @prop {string} EMPTY empty
307
+ * @prop {string} FINISH finish
308
+ * @prop {string} INIT_QUEUE initQueue
309
+ * @prop {string} NO_RELATED noRelated
310
+ * @prop {string} DISCONNECT disconnect
311
+ * @prop {string} DELETE_QUEUE deleteQueue
312
+ * @prop {string} SEARCH_CANCEL searchCancel
313
+ * @prop {string} SEARCH_NO_RESULT searchNoResult
314
+ * @prop {string} SEARCH_DONE searchDone
315
+ * @prop {string} SEARCH_INVALID_ANSWER searchInvalidAnswer
316
+ * @prop {string} SEARCH_RESULT searchResult
317
+ */
149
318
  declare enum Events {
150
319
  ERROR = "error",
151
320
  ADD_LIST = "addList",
@@ -165,6 +334,25 @@ declare enum Events {
165
334
  SEARCH_RESULT = "searchResult"
166
335
  }
167
336
 
337
+ /**
338
+ * Default DisTube audio filters.
339
+ * @typedef {Object} defaultFilters
340
+ * @prop {string} 3d 3d
341
+ * @prop {string} bassboost bassboost
342
+ * @prop {string} echo echo
343
+ * @prop {string} karaoke karaoke
344
+ * @prop {string} nightcore nightcore
345
+ * @prop {string} vaporwave vaporwave
346
+ * @prop {string} flanger flanger
347
+ * @prop {string} gate gate
348
+ * @prop {string} haas haas
349
+ * @prop {string} reverse reverse
350
+ * @prop {string} surround surround
351
+ * @prop {string} mcompand mcompand
352
+ * @prop {string} phaser phaser
353
+ * @prop {string} tremolo tremolo
354
+ * @prop {string} earwax earwax
355
+ */
168
356
  declare const defaultFilters: Filters;
169
357
  declare const defaultOptions: {
170
358
  plugins: never[];
@@ -240,14 +428,39 @@ declare class DisTubeError<T extends string> extends Error {
240
428
  get code(): string;
241
429
  }
242
430
 
431
+ /**
432
+ * Task queuing system
433
+ * @private
434
+ */
243
435
  declare class TaskQueue {
244
436
  #private;
437
+ /**
438
+ * Waits for last task finished and queues a new task
439
+ * @param {boolean} [resolveInfo=false] Whether the task is a resolving info task
440
+ * @returns {Promise<void>}
441
+ */
245
442
  queuing(resolveInfo?: boolean): Promise<void>;
443
+ /**
444
+ * Removes the finished task and processes the next task
445
+ */
246
446
  resolve(): void;
447
+ /**
448
+ * The remaining number of tasks
449
+ * @type {number}
450
+ */
247
451
  get remaining(): number;
452
+ /**
453
+ * Whether or not having a resolving info task
454
+ * @type {boolean}
455
+ */
248
456
  get hasResolveTask(): boolean;
249
457
  }
250
458
 
459
+ /**
460
+ * Class representing a playlist.
461
+ * @prop {string} source Playlist source
462
+ * @template T - The type for the metadata (if any) of the playlist
463
+ */
251
464
  declare class Playlist<T = unknown> implements PlaylistInfo {
252
465
  #private;
253
466
  source: string;
@@ -256,20 +469,49 @@ declare class Playlist<T = unknown> implements PlaylistInfo {
256
469
  url?: string;
257
470
  thumbnail?: string;
258
471
  [x: string]: any;
472
+ /**
473
+ * Create a playlist
474
+ * @param {Song[]|PlaylistInfo} playlist Playlist
475
+ * @param {Object} [options] Optional options
476
+ * @param {Discord.GuildMember} [options.member] Requested user
477
+ * @param {Object} [options.properties] Custom properties
478
+ * @param {T} [options.metadata] Playlist metadata
479
+ */
259
480
  constructor(playlist: Song[] | PlaylistInfo, options?: {
260
481
  member?: GuildMember;
261
482
  properties?: Record<string, any>;
262
483
  metadata?: T;
263
484
  });
485
+ /**
486
+ * Playlist duration in second.
487
+ * @type {number}
488
+ */
264
489
  get duration(): number;
490
+ /**
491
+ * Formatted duration string `hh:mm:ss`.
492
+ * @type {string}
493
+ */
265
494
  get formattedDuration(): string;
495
+ /**
496
+ * User requested.
497
+ * @type {Discord.GuildMember?}
498
+ */
266
499
  get member(): GuildMember | undefined;
267
500
  set member(member: GuildMember | undefined);
501
+ /**
502
+ * User requested.
503
+ * @type {Discord.User?}
504
+ */
268
505
  get user(): discord_js.User | undefined;
269
506
  get metadata(): T;
270
507
  set metadata(metadata: T);
271
508
  }
272
509
 
510
+ /**
511
+ * A abstract class representing a search result.
512
+ * @abstract
513
+ * @private
514
+ */
273
515
  declare abstract class ISearchResult {
274
516
  source: "youtube";
275
517
  abstract type: SearchResultType;
@@ -280,8 +522,16 @@ declare abstract class ISearchResult {
280
522
  name?: string;
281
523
  url?: string;
282
524
  };
525
+ /**
526
+ * Create a search result
527
+ * @param {Object} info ytsr result
528
+ */
283
529
  constructor(info: Video | Playlist$1);
284
530
  }
531
+ /**
532
+ * A class representing a video search result.
533
+ * @extends ISearchResult
534
+ */
285
535
  declare class SearchResultVideo extends ISearchResult {
286
536
  type: SearchResultType.VIDEO;
287
537
  views: number;
@@ -291,13 +541,31 @@ declare class SearchResultVideo extends ISearchResult {
291
541
  thumbnail: string;
292
542
  constructor(info: Video);
293
543
  }
544
+ /**
545
+ * A video or playlist search result
546
+ * @typedef {SearchResultVideo|SearchResultPlaylist} SearchResult
547
+ */
294
548
  type SearchResult = SearchResultVideo | SearchResultPlaylist;
549
+ /**
550
+ * A class representing a playlist search result.
551
+ * @extends ISearchResult
552
+ */
295
553
  declare class SearchResultPlaylist extends ISearchResult {
296
554
  type: SearchResultType.PLAYLIST;
297
555
  length: number;
298
556
  constructor(info: Playlist$1);
299
557
  }
300
558
 
559
+ /**
560
+ * Class representing a song.
561
+ *
562
+ * <info>If {@link Song} is added from a YouTube {@link SearchResult} or {@link Playlist},
563
+ * some info will be missing to save your resources. It will be filled when emitting {@link DisTube#playSong} event.
564
+ *
565
+ * Missing info: {@link Song#likes}, {@link Song#dislikes}, {@link Song#streamURL},
566
+ * {@link Song#related}, {@link Song#chapters}, {@link Song#age_restricted}</info>
567
+ * @template T - The type for the metadata (if any) of the song
568
+ */
301
569
  declare class Song<T = unknown> {
302
570
  #private;
303
571
  source: string;
@@ -321,34 +589,102 @@ declare class Song<T = unknown> {
321
589
  age_restricted: boolean;
322
590
  chapters: Chapter[];
323
591
  reposts: number;
592
+ /**
593
+ * Create a Song
594
+ * @param {ytdl.videoInfo|SearchResult|OtherSongInfo} info Raw info
595
+ * @param {Object} [options] Optional options
596
+ * @param {Discord.GuildMember} [options.member] Requested user
597
+ * @param {string} [options.source="youtube"] Song source
598
+ * @param {T} [options.metadata] Song metadata
599
+ */
324
600
  constructor(info: ytdl.videoInfo | SearchResult | OtherSongInfo | ytdl.relatedVideo | RelatedSong | ytpl.result["items"][number], options?: {
325
601
  member?: GuildMember;
326
602
  source?: string;
327
603
  metadata?: T;
328
604
  });
329
605
  _patchYouTube(i: ytdl.videoInfo | SearchResult): void;
606
+ /**
607
+ * Patch data from other source
608
+ * @param {OtherSongInfo} info Video info
609
+ * @private
610
+ */
330
611
  _patchOther(info: OtherSongInfo): void;
612
+ /**
613
+ * The playlist added this song
614
+ * @type {Playlist?}
615
+ */
331
616
  get playlist(): Playlist | undefined;
332
617
  set playlist(playlist: Playlist | undefined);
618
+ /**
619
+ * User requested.
620
+ * @type {Discord.GuildMember?}
621
+ */
333
622
  get member(): GuildMember | undefined;
334
623
  set member(member: GuildMember | undefined);
624
+ /**
625
+ * User requested.
626
+ * @type {Discord.User?}
627
+ */
335
628
  get user(): discord_js.User | undefined;
336
629
  get metadata(): T;
337
630
  set metadata(metadata: T);
338
631
  }
339
632
 
633
+ /**
634
+ * @private
635
+ * @abstract
636
+ */
340
637
  declare abstract class DisTubeBase {
341
638
  distube: DisTube;
342
639
  constructor(distube: DisTube);
640
+ /**
641
+ * Emit the {@link DisTube} of this base
642
+ * @param {string} eventName Event name
643
+ * @param {...any} args arguments
644
+ * @returns {boolean}
645
+ */
343
646
  emit(eventName: keyof DisTubeEvents, ...args: any): boolean;
647
+ /**
648
+ * Emit error event
649
+ * @param {Error} error error
650
+ * @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
651
+ */
344
652
  emitError(error: Error, channel?: GuildTextBasedChannel): void;
653
+ /**
654
+ * The queue manager
655
+ * @type {QueueManager}
656
+ * @readonly
657
+ */
345
658
  get queues(): QueueManager;
659
+ /**
660
+ * The voice manager
661
+ * @type {DisTubeVoiceManager}
662
+ * @readonly
663
+ */
346
664
  get voices(): DisTubeVoiceManager;
665
+ /**
666
+ * Discord.js client
667
+ * @type {Discord.Client}
668
+ * @readonly
669
+ */
347
670
  get client(): Client;
671
+ /**
672
+ * DisTube options
673
+ * @type {DisTubeOptions}
674
+ * @readonly
675
+ */
348
676
  get options(): Options;
677
+ /**
678
+ * DisTube handler
679
+ * @type {DisTubeHandler}
680
+ * @readonly
681
+ */
349
682
  get handler(): DisTubeHandler;
350
683
  }
351
684
 
685
+ /**
686
+ * Create a voice connection to the voice channel
687
+ */
352
688
  declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
353
689
  #private;
354
690
  readonly id: Snowflake;
@@ -359,22 +695,72 @@ declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
359
695
  emittedError: boolean;
360
696
  isDisconnected: boolean;
361
697
  constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel);
698
+ /**
699
+ * The voice channel id the bot is in
700
+ * @type {Snowflake?}
701
+ */
362
702
  get channelId(): string | undefined;
363
703
  get channel(): VoiceBasedChannel;
364
704
  set channel(channel: VoiceBasedChannel);
705
+ /**
706
+ * Join a voice channel with this connection
707
+ * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel
708
+ * @returns {Promise<DisTubeVoice>}
709
+ */
365
710
  join(channel?: VoiceBasedChannel): Promise<DisTubeVoice>;
711
+ /**
712
+ * Leave the voice channel of this connection
713
+ * @param {Error} [error] Optional, an error to emit with 'error' event.
714
+ */
366
715
  leave(error?: Error): void;
716
+ /**
717
+ * Stop the playing stream
718
+ * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
719
+ * even if the {@link DisTubeVoice#audioResource} has silence padding frames.
720
+ * @private
721
+ */
367
722
  stop(force?: boolean): void;
723
+ /**
724
+ * Play a readable stream
725
+ * @private
726
+ * @param {DisTubeStream} stream Readable stream
727
+ */
368
728
  play(stream: DisTubeStream): void;
369
729
  set volume(volume: number);
370
730
  get volume(): number;
731
+ /**
732
+ * Playback duration of the audio resource in seconds
733
+ * @type {number}
734
+ */
371
735
  get playbackDuration(): number;
372
736
  pause(): void;
373
737
  unpause(): void;
738
+ /**
739
+ * Whether the bot is self-deafened
740
+ * @type {boolean}
741
+ */
374
742
  get selfDeaf(): boolean;
743
+ /**
744
+ * Whether the bot is self-muted
745
+ * @type {boolean}
746
+ */
375
747
  get selfMute(): boolean;
748
+ /**
749
+ * Self-deafens/undeafens the bot.
750
+ * @param {boolean} selfDeaf Whether or not the bot should be self-deafened
751
+ * @returns {boolean} true if the voice state was successfully updated, otherwise false
752
+ */
376
753
  setSelfDeaf(selfDeaf: boolean): boolean;
754
+ /**
755
+ * Self-mutes/unmutes the bot.
756
+ * @param {boolean} selfMute Whether or not the bot should be self-muted
757
+ * @returns {boolean} true if the voice state was successfully updated, otherwise false
758
+ */
377
759
  setSelfMute(selfMute: boolean): boolean;
760
+ /**
761
+ * The voice state of this connection
762
+ * @type {Discord.VoiceState?}
763
+ */
378
764
  get voiceState(): VoiceState | undefined;
379
765
  }
380
766
 
@@ -385,18 +771,54 @@ interface StreamOptions {
385
771
  type?: StreamType;
386
772
  }
387
773
  declare const chooseBestVideoFormat: (formats: ytdl.videoFormat[], isLive?: boolean) => ytdl.videoFormat;
774
+ /**
775
+ * Create a stream to play with {@link DisTubeVoice}
776
+ * @private
777
+ */
388
778
  declare class DisTubeStream {
779
+ /**
780
+ * Create a stream from ytdl video formats
781
+ * @param {ytdl.videoFormat[]} formats ytdl video formats
782
+ * @param {StreamOptions} options options
783
+ * @returns {DisTubeStream}
784
+ * @private
785
+ */
389
786
  static YouTube(formats: ytdl.videoFormat[] | undefined, options?: StreamOptions): DisTubeStream;
787
+ /**
788
+ * Create a stream from a stream url
789
+ * @param {string} url stream url
790
+ * @param {StreamOptions} options options
791
+ * @returns {DisTubeStream}
792
+ * @private
793
+ */
390
794
  static DirectLink(url: string, options?: StreamOptions): DisTubeStream;
391
795
  type: StreamType$1;
392
796
  stream: FFmpeg;
393
797
  url: string;
798
+ /**
799
+ * Create a DisTubeStream to play with {@link DisTubeVoice}
800
+ * @param {string} url Stream URL
801
+ * @param {StreamOptions} options Stream options
802
+ * @private
803
+ */
394
804
  constructor(url: string, options: StreamOptions);
395
805
  }
396
806
 
807
+ /**
808
+ * DisTube's Handler
809
+ * @extends DisTubeBase
810
+ * @private
811
+ */
397
812
  declare class DisTubeHandler extends DisTubeBase {
813
+ #private;
398
814
  constructor(distube: DisTube);
399
815
  get ytdlOptions(): ytdl.getInfoOptions;
816
+ get ytCookie(): string;
817
+ /**
818
+ * @param {string} url url
819
+ * @param {boolean} [basic=false] getBasicInfo?
820
+ * @returns {Promise<ytdl.videoInfo>}
821
+ */
400
822
  getYouTubeInfo(url: string, basic?: boolean): Promise<ytdl.videoInfo>;
401
823
  resolve<T = unknown>(song: Song<T>, options?: Omit<ResolveOptions, "metadata">): Promise<Song<T>>;
402
824
  resolve<T = unknown>(song: Playlist<T>, options?: Omit<ResolveOptions, "metadata">): Promise<Playlist<T>>;
@@ -407,10 +829,48 @@ declare class DisTubeHandler extends DisTubeBase {
407
829
  resolvePlaylist<T = unknown>(playlist: Playlist<T> | Song<T>[] | string, options?: Omit<ResolvePlaylistOptions, "metadata">): Promise<Playlist<T>>;
408
830
  resolvePlaylist<T = undefined>(playlist: Playlist | Song[] | string, options: ResolvePlaylistOptions<T>): Promise<Playlist<T>>;
409
831
  resolvePlaylist(playlist: Playlist | Song[] | string, options?: ResolvePlaylistOptions): Promise<Playlist>;
832
+ /**
833
+ * Search for a song, fire {@link DisTube#event:error} if not found.
834
+ * @param {Discord.Message} message The original message from an user
835
+ * @param {string} query The query string
836
+ * @returns {Promise<SearchResult?>} Song info
837
+ * @throws {DisTubeError}
838
+ */
410
839
  searchSong(message: Message<true>, query: string): Promise<SearchResult | null>;
840
+ /**
841
+ * Create a message collector for selecting search results.
842
+ *
843
+ * Needed events: {@link DisTube#event:searchResult}, {@link DisTube#event:searchCancel},
844
+ * {@link DisTube#event:searchInvalidAnswer}, {@link DisTube#event:searchDone}.
845
+ * @param {Discord.Message} message The original message from an user
846
+ * @param {Array<SearchResult|Song|Playlist>} results The search results
847
+ * @param {string?} [query] The query string
848
+ * @returns {Promise<SearchResult|Song|Playlist|null>} Selected result
849
+ * @throws {DisTubeError}
850
+ */
411
851
  createSearchMessageCollector<R extends SearchResult | Song | Playlist>(message: Message<true>, results: Array<R>, query?: string): Promise<R | null>;
852
+ /**
853
+ * Play or add a {@link Playlist} to the queue.
854
+ * @param {Discord.BaseGuildVoiceChannel} voiceChannel A voice channel
855
+ * @param {Playlist|string} playlist A YouTube playlist url | a Playlist
856
+ * @param {PlayHandlerOptions} [options] Optional options
857
+ * @returns {Promise<void>}
858
+ * @throws {DisTubeError}
859
+ */
412
860
  playPlaylist(voiceChannel: VoiceBasedChannel, playlist: Playlist, options?: PlayHandlerOptions): Promise<void>;
861
+ /**
862
+ * Play or add a {@link Song} to the queue.
863
+ * @param {Discord.BaseGuildVoiceChannel} voiceChannel A voice channel
864
+ * @param {Song} song A YouTube playlist url | a Playlist
865
+ * @param {PlayHandlerOptions} [options] Optional options
866
+ * @returns {Promise<void>}
867
+ * @throws {DisTubeError}
868
+ */
413
869
  playSong(voiceChannel: VoiceBasedChannel, song: Song, options?: PlayHandlerOptions): Promise<void>;
870
+ /**
871
+ * Get {@link Song}'s stream info and attach it to the song.
872
+ * @param {Song} song A Song
873
+ */
414
874
  attachStreamInfo(song: Song): Promise<void>;
415
875
  }
416
876
 
@@ -425,8 +885,7 @@ declare class Options {
425
885
  savePreviousSongs: boolean;
426
886
  searchSongs: number;
427
887
  searchCooldown: number;
428
- youtubeCookie?: string;
429
- youtubeIdentityToken?: string;
888
+ youtubeCookie?: Cookie[] | string;
430
889
  customFilters?: Filters;
431
890
  ytdlOptions: ytdl.getInfoOptions;
432
891
  nsfw: boolean;
@@ -438,11 +897,32 @@ declare class Options {
438
897
  constructor(options: DisTubeOptions);
439
898
  }
440
899
 
900
+ /**
901
+ * Manages the collection of a data model.
902
+ * @abstract
903
+ * @private
904
+ * @extends DisTubeBase
905
+ */
441
906
  declare abstract class BaseManager<V> extends DisTubeBase {
907
+ /**
908
+ * The collection of items for this manager.
909
+ * @type {Collection}
910
+ * @name BaseManager#collection
911
+ */
442
912
  collection: Collection<string, V>;
913
+ /**
914
+ * The size of the collection.
915
+ * @type {number}
916
+ */
443
917
  get size(): number;
444
918
  }
445
919
 
920
+ /**
921
+ * Manages the collection of a data model paired with a guild id.
922
+ * @abstract
923
+ * @private
924
+ * @extends BaseManager
925
+ */
446
926
  declare abstract class GuildIdManager<V> extends BaseManager<V> {
447
927
  add(idOrInstance: GuildIdResolvable, data: V): this | _discordjs_collection.Collection<string, V>;
448
928
  get(idOrInstance: GuildIdResolvable): V | undefined;
@@ -450,34 +930,141 @@ declare abstract class GuildIdManager<V> extends BaseManager<V> {
450
930
  has(idOrInstance: GuildIdResolvable): boolean;
451
931
  }
452
932
 
933
+ /**
934
+ * Manages voice connections for {@link DisTube}
935
+ * @extends BaseManager
936
+ */
453
937
  declare class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {
938
+ /**
939
+ * Get a {@link DisTubeVoice}.
940
+ * @method get
941
+ * @memberof DisTubeVoiceManager#
942
+ * @param {GuildIdResolvable} guild The queue resolvable to resolve
943
+ * @returns {DisTubeVoice?}
944
+ */
945
+ /**
946
+ * Collection of {@link DisTubeVoice}.
947
+ * @name DisTubeVoiceManager#collection
948
+ * @type {Discord.Collection<string, DisTubeVoice>}
949
+ */
950
+ /**
951
+ * Create a {@link DisTubeVoice}
952
+ * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
953
+ * @returns {DisTubeVoice}
954
+ * @private
955
+ */
454
956
  create(channel: VoiceBasedChannel): DisTubeVoice;
957
+ /**
958
+ * Join a voice channel
959
+ * @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
960
+ * @returns {Promise<DisTubeVoice>}
961
+ */
455
962
  join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
963
+ /**
964
+ * Leave the connected voice channel in a guild
965
+ * @param {GuildIdResolvable} guild Queue Resolvable
966
+ */
456
967
  leave(guild: GuildIdResolvable): void;
457
968
  }
458
969
 
970
+ /**
971
+ * Manage filters of a playing {@link Queue}
972
+ * @extends {BaseManager}
973
+ */
459
974
  declare class FilterManager extends BaseManager<Filter> {
460
975
  #private;
976
+ /**
977
+ * Collection of {@link Filter}.
978
+ * @name FilterManager#collection
979
+ * @type {Discord.Collection<string, DisTubeVoice>}
980
+ */
461
981
  queue: Queue;
462
982
  constructor(queue: Queue);
983
+ /**
984
+ * Enable a filter or multiple filters to the manager
985
+ * @param {FilterResolvable|FilterResolvable[]} filterOrFilters The filter or filters to enable
986
+ * @param {boolean} [override=false] Wether or not override the applied filter with new filter value
987
+ * @returns {FilterManager}
988
+ */
463
989
  add(filterOrFilters: FilterResolvable | FilterResolvable[], override?: boolean): this;
990
+ /**
991
+ * Clear enabled filters of the manager
992
+ * @returns {FilterManager}
993
+ */
464
994
  clear(): this;
995
+ /**
996
+ * Set the filters applied to the manager
997
+ * @param {FilterResolvable[]} filters The filters to apply
998
+ * @returns {FilterManager}
999
+ */
465
1000
  set(filters: FilterResolvable[]): this;
1001
+ /**
1002
+ * Disable a filter or multiple filters
1003
+ * @param {FilterResolvable|FilterResolvable[]} filterOrFilters The filter or filters to disable
1004
+ * @returns {FilterManager}
1005
+ */
466
1006
  remove(filterOrFilters: FilterResolvable | FilterResolvable[]): this;
1007
+ /**
1008
+ * Check whether a filter enabled or not
1009
+ * @param {FilterResolvable} filter The filter to check
1010
+ * @returns {boolean}
1011
+ */
467
1012
  has(filter: FilterResolvable): boolean;
1013
+ /**
1014
+ * Array of enabled filter names
1015
+ * @type {Array<string>}
1016
+ * @readonly
1017
+ */
468
1018
  get names(): string[];
1019
+ /**
1020
+ * Array of enabled filters
1021
+ * @type {Array<Filter>}
1022
+ * @readonly
1023
+ */
469
1024
  get values(): Filter[];
470
1025
  get ffmpegArgs(): string[];
471
1026
  toString(): string;
472
1027
  }
473
1028
 
1029
+ /**
1030
+ * Queue manager
1031
+ * @extends GuildIdManager
1032
+ */
474
1033
  declare class QueueManager extends GuildIdManager<Queue> {
475
1034
  #private;
1035
+ /**
1036
+ * Collection of {@link Queue}.
1037
+ * @name QueueManager#collection
1038
+ * @type {Discord.Collection<string, Queue>}
1039
+ */
1040
+ /**
1041
+ * Create a {@link Queue}
1042
+ * @private
1043
+ * @param {Discord.BaseGuildVoiceChannel} channel A voice channel
1044
+ * @param {Song|Song[]} song First song
1045
+ * @param {Discord.BaseGuildTextChannel} textChannel Default text channel
1046
+ * @returns {Promise<Queue|true>} Returns `true` if encounter an error
1047
+ */
476
1048
  create(channel: VoiceBasedChannel, song: Song[] | Song, textChannel?: GuildTextBasedChannel): Promise<Queue | true>;
1049
+ /**
1050
+ * Create a ytdl stream
1051
+ * @param {Queue} queue Queue
1052
+ * @returns {DisTubeStream}
1053
+ */
477
1054
  createStream(queue: Queue): DisTubeStream;
1055
+ /**
1056
+ * Play a song on voice connection
1057
+ * @private
1058
+ * @param {Queue} queue The guild queue
1059
+ * @returns {Promise<boolean>} error?
1060
+ */
478
1061
  playSong(queue: Queue): Promise<boolean>;
479
1062
  }
480
1063
 
1064
+ /**
1065
+ * Represents a queue.
1066
+ * @extends DisTubeBase
1067
+ */
481
1068
  declare class Queue extends DisTubeBase {
482
1069
  #private;
483
1070
  readonly id: Snowflake;
@@ -496,53 +1083,240 @@ declare class Queue extends DisTubeBase {
496
1083
  _emptyTimeout?: NodeJS.Timeout;
497
1084
  _taskQueue: TaskQueue;
498
1085
  _listeners?: DisTubeVoiceEvents;
1086
+ /**
1087
+ * Create a queue for the guild
1088
+ * @param {DisTube} distube DisTube
1089
+ * @param {DisTubeVoice} voice Voice connection
1090
+ * @param {Song|Song[]} song First song(s)
1091
+ * @param {Discord.BaseGuildTextChannel?} textChannel Default text channel
1092
+ */
499
1093
  constructor(distube: DisTube, voice: DisTubeVoice, song: Song | Song[], textChannel?: GuildTextBasedChannel);
1094
+ /**
1095
+ * The client user as a `GuildMember` of this queue's guild
1096
+ * @type {Discord.GuildMember?}
1097
+ */
500
1098
  get clientMember(): discord_js.GuildMember | undefined;
1099
+ /**
1100
+ * The filter manager of the queue
1101
+ * @type {FilterManager}
1102
+ * @readonly
1103
+ */
501
1104
  get filters(): FilterManager;
1105
+ /**
1106
+ * Formatted duration string.
1107
+ * @type {string}
1108
+ * @readonly
1109
+ */
502
1110
  get formattedDuration(): string;
1111
+ /**
1112
+ * Queue's duration.
1113
+ * @type {number}
1114
+ * @readonly
1115
+ */
503
1116
  get duration(): number;
1117
+ /**
1118
+ * What time in the song is playing (in seconds).
1119
+ * @type {number}
1120
+ * @readonly
1121
+ */
504
1122
  get currentTime(): number;
1123
+ /**
1124
+ * Formatted {@link Queue#currentTime} string.
1125
+ * @type {string}
1126
+ * @readonly
1127
+ */
505
1128
  get formattedCurrentTime(): string;
1129
+ /**
1130
+ * The voice channel playing in.
1131
+ * @type {Discord.VoiceChannel|Discord.StageChannel|null}
1132
+ * @readonly
1133
+ */
506
1134
  get voiceChannel(): discord_js.VoiceBasedChannel | null;
507
1135
  get volume(): number;
508
1136
  set volume(value: number);
1137
+ /**
1138
+ * @private
1139
+ * Add a Song or an array of Song to the queue
1140
+ * @param {Song|Song[]} song Song to add
1141
+ * @param {number} [position=0] Position to add, <= 0 to add to the end of the queue
1142
+ * @throws {Error}
1143
+ * @returns {Queue} The guild queue
1144
+ */
509
1145
  addToQueue(song: Song | Song[], position?: number): Queue;
1146
+ /**
1147
+ * Pause the guild stream
1148
+ * @returns {Queue} The guild queue
1149
+ */
510
1150
  pause(): Queue;
1151
+ /**
1152
+ * Resume the guild stream
1153
+ * @returns {Queue} The guild queue
1154
+ */
511
1155
  resume(): Queue;
1156
+ /**
1157
+ * Set the guild stream's volume
1158
+ * @param {number} percent The percentage of volume you want to set
1159
+ * @returns {Queue} The guild queue
1160
+ */
512
1161
  setVolume(percent: number): Queue;
1162
+ /**
1163
+ * Skip the playing song if there is a next song in the queue.
1164
+ * <info>If {@link Queue#autoplay} is `true` and there is no up next song,
1165
+ * DisTube will add and play a related song.</info>
1166
+ * @returns {Promise<Song>} The song will skip to
1167
+ * @throws {Error}
1168
+ */
513
1169
  skip(): Promise<Song>;
1170
+ /**
1171
+ * Play the previous song if exists
1172
+ * @returns {Promise<Song>} The guild queue
1173
+ * @throws {Error}
1174
+ */
514
1175
  previous(): Promise<Song>;
1176
+ /**
1177
+ * Shuffle the queue's songs
1178
+ * @returns {Promise<Queue>} The guild queue
1179
+ */
515
1180
  shuffle(): Promise<Queue>;
1181
+ /**
1182
+ * Jump to the song position in the queue.
1183
+ * The next one is 1, 2,...
1184
+ * The previous one is -1, -2,...
1185
+ * @param {number} position The song position to play
1186
+ * @returns {Promise<Song>} The new Song will be played
1187
+ * @throws {Error} if `num` is invalid number
1188
+ */
516
1189
  jump(position: number): Promise<Song>;
1190
+ /**
1191
+ * Set the repeat mode of the guild queue.\
1192
+ * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`
1193
+ * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)
1194
+ * @returns {RepeatMode} The new repeat mode
1195
+ */
517
1196
  setRepeatMode(mode?: RepeatMode): RepeatMode;
1197
+ /**
1198
+ * Set the playing time to another position
1199
+ * @param {number} time Time in seconds
1200
+ * @returns {Queue} The guild queue
1201
+ */
518
1202
  seek(time: number): Queue;
1203
+ /**
1204
+ * Add a related song of the playing song to the queue
1205
+ * @returns {Promise<Song>} The added song
1206
+ * @throws {Error}
1207
+ */
519
1208
  addRelatedSong(): Promise<Song>;
1209
+ /**
1210
+ * Stop the guild stream and delete the queue
1211
+ */
520
1212
  stop(): Promise<void>;
1213
+ /**
1214
+ * Remove the queue from the manager
1215
+ * (This does not leave the voice channel even if {@link DisTubeOptions|DisTubeOptions.leaveOnStop} is enabled)
1216
+ * @private
1217
+ */
521
1218
  remove(): void;
1219
+ /**
1220
+ * Toggle autoplay mode
1221
+ * @returns {boolean} Autoplay mode state
1222
+ */
522
1223
  toggleAutoplay(): boolean;
523
1224
  }
524
1225
 
1226
+ /**
1227
+ * DisTube Plugin
1228
+ * @abstract
1229
+ * @private
1230
+ */
525
1231
  declare abstract class Plugin {
526
1232
  abstract type: PluginType;
527
1233
  distube: DisTube;
528
1234
  init(distube: DisTube): void;
1235
+ /**
1236
+ * Type of the plugin
1237
+ * @name Plugin#type
1238
+ * @type {PluginType}
1239
+ */
1240
+ /**
1241
+ * Emit an event to the {@link DisTube} class
1242
+ * @param {string} eventName Event name
1243
+ * @param {...any} args arguments
1244
+ * @returns {boolean}
1245
+ */
529
1246
  emit(eventName: keyof DisTubeEvents, ...args: any): boolean;
1247
+ /**
1248
+ * Emit error event to the {@link DisTube} class
1249
+ * @param {Error} error error
1250
+ * @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
1251
+ */
530
1252
  emitError(error: Error, channel?: GuildTextBasedChannel): void;
1253
+ /**
1254
+ * The queue manager
1255
+ * @type {QueueManager}
1256
+ * @readonly
1257
+ */
531
1258
  get queues(): QueueManager;
1259
+ /**
1260
+ * The voice manager
1261
+ * @type {DisTubeVoiceManager}
1262
+ * @readonly
1263
+ */
532
1264
  get voices(): DisTubeVoiceManager;
1265
+ /**
1266
+ * Discord.js client
1267
+ * @type {Discord.Client}
1268
+ * @readonly
1269
+ */
533
1270
  get client(): Client;
1271
+ /**
1272
+ * DisTube options
1273
+ * @type {DisTubeOptions}
1274
+ * @readonly
1275
+ */
534
1276
  get options(): Options;
1277
+ /**
1278
+ * DisTube handler
1279
+ * @type {DisTubeHandler}
1280
+ * @readonly
1281
+ */
535
1282
  get handler(): DisTubeHandler;
1283
+ /**
1284
+ * Check if the string is working with this plugin
1285
+ * @param {string} _string Input string
1286
+ * @returns {boolean|Promise<boolean>}
1287
+ */
536
1288
  validate(_string: string): Awaitable<boolean>;
1289
+ /**
1290
+ * Get the stream url from {@link Song#url}. Returns {@link Song#url} by default.
1291
+ * Not needed if the plugin plays song from YouTube.
1292
+ * @param {string} url Input url
1293
+ * @returns {string|Promise<string>}
1294
+ */
537
1295
  getStreamURL(url: string): Awaitable<string>;
1296
+ /**
1297
+ * Get related songs from a supported url. {@link Song#member} should be `undefined`.
1298
+ * Not needed to add {@link Song#related} because it will be added with this function later.
1299
+ * @param {string} _url Input url
1300
+ * @returns {Song[]|Promise<Song[]>}
1301
+ */
538
1302
  getRelatedSongs(_url: string): Awaitable<RelatedSong[]>;
539
1303
  }
540
1304
 
1305
+ /**
1306
+ * Custom Plugin
1307
+ * @extends Plugin
1308
+ * @abstract
1309
+ */
541
1310
  declare abstract class CustomPlugin extends Plugin {
542
1311
  readonly type = PluginType.CUSTOM;
543
1312
  abstract play(voiceChannel: VoiceBasedChannel, song: string, options: PlayOptions): Awaitable<void>;
544
1313
  }
545
1314
 
1315
+ /**
1316
+ * Extractor Plugin
1317
+ * @extends Plugin
1318
+ * @abstract
1319
+ */
546
1320
  declare abstract class ExtractorPlugin extends Plugin {
547
1321
  readonly type = PluginType.EXTRACTOR;
548
1322
  abstract resolve<T = unknown>(url: string, options: {
@@ -551,12 +1325,41 @@ declare abstract class ExtractorPlugin extends Plugin {
551
1325
  }): Awaitable<Song<T> | Playlist<T>>;
552
1326
  }
553
1327
 
1328
+ /**
1329
+ * Format duration to string
1330
+ * @param {number} sec Duration in seconds
1331
+ * @returns {string}
1332
+ */
554
1333
  declare function formatDuration(sec: number): string;
1334
+ /**
1335
+ * Convert formatted duration to seconds
1336
+ * @param {*} input Formatted duration string
1337
+ * @returns {number}
1338
+ */
555
1339
  declare function toSecond(input: any): number;
1340
+ /**
1341
+ * Parse number from input
1342
+ * @param {*} input Any
1343
+ * @returns {number}
1344
+ */
556
1345
  declare function parseNumber(input: any): number;
557
1346
  declare const SUPPORTED_PROTOCOL: readonly ["https:", "http:", "file:"];
1347
+ /**
1348
+ * Check if the string is an URL
1349
+ * @param {string} input input
1350
+ * @returns {boolean}
1351
+ */
558
1352
  declare function isURL(input: any): input is `${(typeof SUPPORTED_PROTOCOL)[number]}//${string}`;
1353
+ /**
1354
+ * Check if the Client has enough intents to using DisTube
1355
+ * @param {ClientOptions} options options
1356
+ */
559
1357
  declare function checkIntents(options: ClientOptions): void;
1358
+ /**
1359
+ * Check if the voice channel is empty
1360
+ * @param {Discord.VoiceState} voiceState voiceState
1361
+ * @returns {boolean}
1362
+ */
560
1363
  declare function isVoiceChannelEmpty(voiceState: VoiceState): boolean;
561
1364
  declare function isSnowflake(id: any): id is Snowflake;
562
1365
  declare function isMemberInstance(member: any): member is GuildMember;
@@ -572,17 +1375,24 @@ declare function isRecord<T = unknown>(obj: any): obj is Record<string, T>;
572
1375
  type KeyOf<T> = T extends object ? (keyof T)[] : [];
573
1376
  declare function objectKeys<T>(obj: T): KeyOf<T>;
574
1377
  declare function isNsfwChannel(channel?: GuildTextBasedChannel): boolean;
1378
+ type Falsy = undefined | null | false | 0 | "";
1379
+ declare const isTruthy: <T>(x: T | Falsy) => x is T;
575
1380
 
576
1381
  declare class DirectLinkPlugin extends ExtractorPlugin {
577
1382
  validate(url: string): Promise<boolean>;
578
1383
  resolve(url: string, options?: {
579
1384
  member?: GuildMember;
580
1385
  metadata?: any;
581
- }): Promise<Song<any>>;
1386
+ }): Song<any>;
582
1387
  }
583
1388
 
584
1389
  declare const version: string;
1390
+ /**
1391
+ * DisTube class
1392
+ * @extends EventEmitter
1393
+ */
585
1394
  declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
1395
+ #private;
586
1396
  readonly handler: DisTubeHandler;
587
1397
  readonly options: Options;
588
1398
  readonly client: Client;
@@ -591,10 +1401,71 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
591
1401
  readonly extractorPlugins: ExtractorPlugin[];
592
1402
  readonly customPlugins: CustomPlugin[];
593
1403
  readonly filters: Filters;
1404
+ /**
1405
+ * @deprecated Use `youtubeCookie: Cookie[]` instead. Guide: {@link https://distube.js.org/#/docs/DisTube/main/general/cookie YouTube Cookies}
1406
+ */
1407
+ constructor(client: Client, otp: DisTubeOptions & {
1408
+ youtubeCookie: string;
1409
+ });
1410
+ /**
1411
+ * Create a new DisTube class.
1412
+ * @param {Discord.Client} client Discord.JS client
1413
+ * @param {DisTubeOptions} [otp] Custom DisTube options
1414
+ * @throws {DisTubeError}
1415
+ * @example
1416
+ * const Discord = require('discord.js'),
1417
+ * DisTube = require('distube'),
1418
+ * client = new Discord.Client();
1419
+ * // Create a new DisTube
1420
+ * const distube = new DisTube.default(client, { searchSongs: 10 });
1421
+ * // client.DisTube = distube // make it access easily
1422
+ * client.login("Your Discord Bot Token")
1423
+ */
594
1424
  constructor(client: Client, otp?: DisTubeOptions);
595
1425
  static get version(): string;
1426
+ /**
1427
+ * DisTube version
1428
+ * @type {string}
1429
+ */
596
1430
  get version(): string;
1431
+ /**
1432
+ * Play / add a song or playlist from url. Search and play a song if it is not a valid url.
1433
+ *
1434
+ * @param {Discord.BaseGuildVoiceChannel} voiceChannel The channel will be joined if the bot isn't in any channels,
1435
+ * the bot will be moved to this channel if {@link DisTubeOptions}.joinNewVoiceChannel is `true`
1436
+ * @param {string|Song|SearchResult|Playlist} song URL | Search string |
1437
+ * {@link Song} | {@link SearchResult} | {@link Playlist}
1438
+ * @param {PlayOptions} [options] Optional options
1439
+ * @throws {DisTubeError}
1440
+ * @example
1441
+ * client.on('message', (message) => {
1442
+ * if (!message.content.startsWith(config.prefix)) return;
1443
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1444
+ * const command = args.shift();
1445
+ * if (command == "play")
1446
+ * distube.play(message.member.voice.channel, args.join(" "), {
1447
+ * member: message.member,
1448
+ * textChannel: message.channel,
1449
+ * message
1450
+ * });
1451
+ * });
1452
+ * @returns {Promise<void>}
1453
+ */
597
1454
  play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist, options?: PlayOptions): Promise<void>;
1455
+ /**
1456
+ * Create a custom playlist
1457
+ * @returns {Promise<Playlist>}
1458
+ * @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
1459
+ * @param {CustomPlaylistOptions} [options] Optional options
1460
+ * @example
1461
+ * const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
1462
+ * const playlist = await distube.createCustomPlaylist(songs, {
1463
+ * member: message.member,
1464
+ * properties: { name: "My playlist name", source: "custom" },
1465
+ * parallel: true
1466
+ * });
1467
+ * distube.play(voiceChannel, playlist, { ... });
1468
+ */
598
1469
  createCustomPlaylist(songs: (string | Song | SearchResult)[], options?: CustomPlaylistOptions): Promise<Playlist>;
599
1470
  search(string: string, options?: {
600
1471
  type?: SearchResultType.VIDEO;
@@ -614,20 +1485,216 @@ declare class DisTube extends TypedEmitter<TypedDisTubeEvents> {
614
1485
  safeSearch?: boolean;
615
1486
  retried?: boolean;
616
1487
  }): Promise<Array<SearchResult>>;
1488
+ /**
1489
+ * Get the guild queue
1490
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1491
+ * @returns {Queue?}
1492
+ * @throws {Error}
1493
+ * @example
1494
+ * client.on('message', (message) => {
1495
+ * if (!message.content.startsWith(config.prefix)) return;
1496
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1497
+ * const command = args.shift();
1498
+ * if (command == "queue") {
1499
+ * const queue = distube.getQueue(message);
1500
+ * message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
1501
+ * `**${id+1}**. [${song.name}](${song.url}) - \`${song.formattedDuration}\``
1502
+ * ).join("\n"));
1503
+ * }
1504
+ * });
1505
+ */
617
1506
  getQueue(guild: GuildIdResolvable): Queue | undefined;
1507
+ /**
1508
+ * Pause the guild stream
1509
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1510
+ * @returns {Queue} The guild queue
1511
+ * @throws {Error}
1512
+ */
618
1513
  pause(guild: GuildIdResolvable): Queue;
1514
+ /**
1515
+ * Resume the guild stream
1516
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1517
+ * @returns {Queue} The guild queue
1518
+ * @throws {Error}
1519
+ */
619
1520
  resume(guild: GuildIdResolvable): Queue;
1521
+ /**
1522
+ * Stop the guild stream
1523
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1524
+ * @returns {Promise<void>}
1525
+ * @throws {Error}
1526
+ * @example
1527
+ * client.on('message', (message) => {
1528
+ * if (!message.content.startsWith(config.prefix)) return;
1529
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1530
+ * const command = args.shift();
1531
+ * if (command == "stop") {
1532
+ * distube.stop(message);
1533
+ * message.channel.send("Stopped the queue!");
1534
+ * }
1535
+ * });
1536
+ */
620
1537
  stop(guild: GuildIdResolvable): Promise<void>;
1538
+ /**
1539
+ * Set the guild stream's volume
1540
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1541
+ * @param {number} percent The percentage of volume you want to set
1542
+ * @returns {Queue} The guild queue
1543
+ * @throws {Error}
1544
+ * @example
1545
+ * client.on('message', (message) => {
1546
+ * if (!message.content.startsWith(config.prefix)) return;
1547
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1548
+ * const command = args.shift();
1549
+ * if (command == "volume")
1550
+ * distube.setVolume(message, Number(args[0]));
1551
+ * });
1552
+ */
621
1553
  setVolume(guild: GuildIdResolvable, percent: number): Queue;
1554
+ /**
1555
+ * Skip the playing song if there is a next song in the queue.
1556
+ * <info>If {@link Queue#autoplay} is `true` and there is no up next song,
1557
+ * DisTube will add and play a related song.</info>
1558
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1559
+ * @returns {Promise<Song>} The new Song will be played
1560
+ * @throws {Error}
1561
+ * @example
1562
+ * client.on('message', (message) => {
1563
+ * if (!message.content.startsWith(config.prefix)) return;
1564
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1565
+ * const command = args.shift();
1566
+ * if (command == "skip")
1567
+ * distube.skip(message);
1568
+ * });
1569
+ */
622
1570
  skip(guild: GuildIdResolvable): Promise<Song>;
1571
+ /**
1572
+ * Play the previous song
1573
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1574
+ * @returns {Promise<Song>} The new Song will be played
1575
+ * @throws {Error}
1576
+ * @example
1577
+ * client.on('message', (message) => {
1578
+ * if (!message.content.startsWith(config.prefix)) return;
1579
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1580
+ * const command = args.shift();
1581
+ * if (command == "previous")
1582
+ * distube.previous(message);
1583
+ * });
1584
+ */
623
1585
  previous(guild: GuildIdResolvable): Promise<Song>;
1586
+ /**
1587
+ * Shuffle the guild queue songs
1588
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1589
+ * @returns {Promise<Queue>} The guild queue
1590
+ * @example
1591
+ * client.on('message', (message) => {
1592
+ * if (!message.content.startsWith(config.prefix)) return;
1593
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1594
+ * const command = args.shift();
1595
+ * if (command == "shuffle")
1596
+ * distube.shuffle(message);
1597
+ * });
1598
+ */
624
1599
  shuffle(guild: GuildIdResolvable): Promise<Queue>;
1600
+ /**
1601
+ * Jump to the song number in the queue.
1602
+ * The next one is 1, 2,...
1603
+ * The previous one is -1, -2,...
1604
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1605
+ * @param {number} num The song number to play
1606
+ * @returns {Promise<Song>} The new Song will be played
1607
+ * @throws {Error} if `num` is invalid number (0 < num < {@link Queue#songs}.length)
1608
+ * @example
1609
+ * client.on('message', (message) => {
1610
+ * if (!message.content.startsWith(config.prefix)) return;
1611
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1612
+ * const command = args.shift();
1613
+ * if (command == "jump")
1614
+ * distube.jump(message, parseInt(args[0]))
1615
+ * .catch(err => message.channel.send("Invalid song number."));
1616
+ * });
1617
+ */
625
1618
  jump(guild: GuildIdResolvable, num: number): Promise<Song>;
1619
+ /**
1620
+ * Set the repeat mode of the guild queue.\
1621
+ * Toggle mode `(Disabled -> Song -> Queue -> Disabled ->...)` if `mode` is `undefined`
1622
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1623
+ * @param {RepeatMode?} [mode] The repeat modes (toggle if `undefined`)
1624
+ * @returns {RepeatMode} The new repeat mode
1625
+ * @example
1626
+ * client.on('message', (message) => {
1627
+ * if (!message.content.startsWith(config.prefix)) return;
1628
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1629
+ * const command = args.shift();
1630
+ * if (command == "repeat") {
1631
+ * let mode = distube.setRepeatMode(message, parseInt(args[0]));
1632
+ * mode = mode ? mode == 2 ? "Repeat queue" : "Repeat song" : "Off";
1633
+ * message.channel.send("Set repeat mode to `" + mode + "`");
1634
+ * }
1635
+ * });
1636
+ * @example
1637
+ * const { RepeatMode } = require("distube");
1638
+ * let mode;
1639
+ * switch(distube.setRepeatMode(message, parseInt(args[0]))) {
1640
+ * case RepeatMode.DISABLED:
1641
+ * mode = "Off";
1642
+ * break;
1643
+ * case RepeatMode.SONG:
1644
+ * mode = "Repeat a song";
1645
+ * break;
1646
+ * case RepeatMode.QUEUE:
1647
+ * mode = "Repeat all queue";
1648
+ * break;
1649
+ * }
1650
+ * message.channel.send("Set repeat mode to `" + mode + "`");
1651
+ */
626
1652
  setRepeatMode(guild: GuildIdResolvable, mode?: number): number;
1653
+ /**
1654
+ * Toggle autoplay mode
1655
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1656
+ * @returns {boolean} Autoplay mode state
1657
+ * @throws {Error}
1658
+ * @example
1659
+ * client.on('message', (message) => {
1660
+ * if (!message.content.startsWith(config.prefix)) return;
1661
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1662
+ * const command = args.shift();
1663
+ * if (command == "autoplay") {
1664
+ * const mode = distube.toggleAutoplay(message);
1665
+ * message.channel.send("Set autoplay mode to `" + (mode ? "On" : "Off") + "`");
1666
+ * }
1667
+ * });
1668
+ */
627
1669
  toggleAutoplay(guild: GuildIdResolvable): boolean;
1670
+ /**
1671
+ * Add related song to the queue
1672
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1673
+ * @returns {Promise<Song>} The guild queue
1674
+ */
628
1675
  addRelatedSong(guild: GuildIdResolvable): Promise<Song>;
1676
+ /**
1677
+ * Set the playing time to another position
1678
+ * @param {GuildIdResolvable} guild The type can be resolved to give a {@link Queue}
1679
+ * @param {number} time Time in seconds
1680
+ * @returns {Queue} Seeked queue
1681
+ * @example
1682
+ * client.on('message', message => {
1683
+ * if (!message.content.startsWith(config.prefix)) return;
1684
+ * const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
1685
+ * const command = args.shift();
1686
+ * if (command = 'seek')
1687
+ * distube.seek(message, Number(args[0]));
1688
+ * });
1689
+ */
629
1690
  seek(guild: GuildIdResolvable, time: number): Queue;
1691
+ /**
1692
+ * Emit error event
1693
+ * @param {Error} error error
1694
+ * @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
1695
+ * @private
1696
+ */
630
1697
  emitError(error: Error, channel?: GuildTextBasedChannel): void;
631
1698
  }
632
1699
 
633
- export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DirectLinkPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, Events, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, TypedDisTubeEvents, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isNsfwChannel, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isURL, isVoiceChannelEmpty, objectKeys, parseNumber, resolveGuildId, toSecond, version };
1700
+ export { Awaitable, BaseManager, Chapter, CustomPlaylistOptions, CustomPlugin, DirectLinkPlugin, DisTube, DisTubeBase, DisTubeError, DisTubeEvents, DisTubeHandler, DisTubeOptions, DisTubeStream, DisTubeVoice, DisTubeVoiceEvents, DisTubeVoiceManager, Events, ExtractorPlugin, Filter, FilterManager, FilterResolvable, Filters, GuildIdManager, GuildIdResolvable, Options, OtherSongInfo, PlayHandlerOptions, PlayOptions, Playlist, PlaylistInfo, Plugin, PluginType, Queue, QueueManager, RelatedSong, RepeatMode, ResolveOptions, ResolvePlaylistOptions, SearchResult, SearchResultPlaylist, SearchResultType, SearchResultVideo, Song, StreamType, TaskQueue, TypedDisTubeEvents, checkIntents, checkInvalidKey, chooseBestVideoFormat, DisTube as default, defaultFilters, defaultOptions, formatDuration, isClientInstance, isGuildInstance, isMemberInstance, isMessageInstance, isNsfwChannel, isObject, isRecord, isSnowflake, isSupportedVoiceChannel, isTextChannelInstance, isTruthy, isURL, isVoiceChannelEmpty, objectKeys, parseNumber, resolveGuildId, toSecond, version };