distube 3.0.5 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dist/DisTube.d.ts +98 -37
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +133 -86
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +12 -13
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +12 -13
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeBase.d.ts +3 -4
- package/dist/core/DisTubeBase.d.ts.map +1 -1
- package/dist/core/DisTubeBase.js +1 -2
- package/dist/core/DisTubeBase.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +37 -25
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +69 -60
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeOptions.d.ts +1 -2
- package/dist/core/DisTubeOptions.d.ts.map +1 -1
- package/dist/core/DisTubeOptions.js +64 -58
- package/dist/core/DisTubeOptions.js.map +1 -1
- package/dist/core/DisTubeStream.d.ts +1 -1
- package/dist/core/DisTubeStream.d.ts.map +1 -1
- package/dist/core/DisTubeStream.js +0 -1
- package/dist/core/DisTubeStream.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/manager/BaseManager.d.ts +8 -4
- package/dist/core/manager/BaseManager.d.ts.map +1 -1
- package/dist/core/manager/BaseManager.js +11 -13
- package/dist/core/manager/BaseManager.js.map +1 -1
- package/dist/core/manager/QueueManager.d.ts +11 -38
- package/dist/core/manager/QueueManager.d.ts.map +1 -1
- package/dist/core/manager/QueueManager.js +116 -129
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts +10 -13
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +38 -23
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.d.ts +6 -6
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.js +3 -3
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
- package/dist/plugin/http.d.ts +5 -3
- package/dist/plugin/http.d.ts.map +1 -1
- package/dist/plugin/http.js +3 -5
- package/dist/plugin/http.js.map +1 -1
- package/dist/plugin/https.d.ts +10 -5
- package/dist/plugin/https.d.ts.map +1 -1
- package/dist/plugin/https.js +5 -8
- package/dist/plugin/https.js.map +1 -1
- package/dist/plugin/youtube-dl.d.ts +5 -4
- package/dist/plugin/youtube-dl.d.ts.map +1 -1
- package/dist/plugin/youtube-dl.js +7 -11
- package/dist/plugin/youtube-dl.js.map +1 -1
- package/dist/struct/CustomPlugin.d.ts +37 -17
- package/dist/struct/CustomPlugin.d.ts.map +1 -1
- package/dist/struct/CustomPlugin.js +18 -19
- package/dist/struct/CustomPlugin.js.map +1 -1
- package/dist/struct/DisTubeError.d.ts +4 -3
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +5 -7
- package/dist/struct/DisTubeError.js.map +1 -1
- package/dist/struct/ExtractorPlugin.d.ts +25 -15
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
- package/dist/struct/ExtractorPlugin.js +14 -16
- package/dist/struct/ExtractorPlugin.js.map +1 -1
- package/dist/struct/Playlist.d.ts +24 -8
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +24 -8
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Plugin.d.ts +4 -12
- package/dist/struct/Plugin.d.ts.map +1 -1
- package/dist/struct/Plugin.js +1 -11
- package/dist/struct/Plugin.js.map +1 -1
- package/dist/struct/Queue.d.ts +5 -6
- package/dist/struct/Queue.d.ts.map +1 -1
- package/dist/struct/Queue.js +2 -3
- package/dist/struct/Queue.js.map +1 -1
- package/dist/struct/SearchResult.d.ts +0 -1
- package/dist/struct/SearchResult.d.ts.map +1 -1
- package/dist/struct/SearchResult.js +0 -1
- package/dist/struct/SearchResult.js.map +1 -1
- package/dist/struct/Song.d.ts +26 -10
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +32 -17
- package/dist/struct/Song.js.map +1 -1
- package/dist/struct/TaskQueue.d.ts +1 -6
- package/dist/struct/TaskQueue.d.ts.map +1 -1
- package/dist/struct/TaskQueue.js +13 -6
- package/dist/struct/TaskQueue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +12 -12
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +4 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +1 -2
- package/dist/util.js.map +1 -1
- package/package.json +21 -17
package/README.md
CHANGED
|
@@ -30,12 +30,6 @@ A Discord.js module to simplify your music commands and play songs with audio fi
|
|
|
30
30
|
- Autoplay related songs
|
|
31
31
|
- Plugin system to support more sites ([Plugin List](https://distube.js.org/#/docs/DisTube/stable/plugin/list))
|
|
32
32
|
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
```npm
|
|
36
|
-
npm install distube@latest
|
|
37
|
-
```
|
|
38
|
-
|
|
39
33
|
### Requirement
|
|
40
34
|
|
|
41
35
|
- Node v12 or higher
|
|
@@ -46,6 +40,12 @@ npm install distube@latest
|
|
|
46
40
|
- [sodium](https://www.npmjs.com/package/sodium) or [libsodium-wrappers](https://www.npmjs.com/package/libsodium-wrappers)
|
|
47
41
|
- [python](https://www.python.org/) _(Optional - For [`youtube-dl`](https://youtube-dl.org/) to support [700+ more sites](https://ytdl-org.github.io/youtube-dl/supportedsites.html).)_
|
|
48
42
|
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```npm
|
|
46
|
+
npm install distube@latest
|
|
47
|
+
```
|
|
48
|
+
|
|
49
49
|
## Documentation
|
|
50
50
|
|
|
51
51
|
Read DisTube's definitions, properties and events details in the [Documentation page](https://distube.js.org/).
|
package/dist/DisTube.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { TypedEmitter } from "tiny-typed-emitter";
|
|
2
|
-
import { DisTubeHandler, DisTubeVoiceManager, Options, Playlist, Queue, QueueManager, SearchResult } from ".";
|
|
3
|
-
import type { Client, GuildMember,
|
|
4
|
-
import type { CustomPlugin, DisTubeEvents, DisTubeOptions, ExtractorPlugin, Filters, GuildIDResolvable
|
|
2
|
+
import { DisTubeHandler, DisTubeVoiceManager, Options, Playlist, Queue, QueueManager, SearchResult, Song } from ".";
|
|
3
|
+
import type { Client, GuildMember, GuildTextBasedChannel, Message, VoiceBasedChannel } from "discord.js";
|
|
4
|
+
import type { CustomPlugin, DisTubeEvents, DisTubeOptions, ExtractorPlugin, Filters, GuildIDResolvable } from ".";
|
|
5
5
|
/**
|
|
6
6
|
* DisTube class
|
|
7
7
|
* @extends EventEmitter
|
|
8
8
|
*/
|
|
9
9
|
export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
10
|
-
handler: DisTubeHandler;
|
|
11
|
-
options: Options;
|
|
12
|
-
client: Client;
|
|
13
|
-
queues: QueueManager;
|
|
14
|
-
voices: DisTubeVoiceManager;
|
|
15
|
-
extractorPlugins: ExtractorPlugin[];
|
|
16
|
-
customPlugins: CustomPlugin[];
|
|
17
|
-
filters: Filters;
|
|
10
|
+
readonly handler: DisTubeHandler;
|
|
11
|
+
readonly options: Options;
|
|
12
|
+
readonly client: Client;
|
|
13
|
+
readonly queues: QueueManager;
|
|
14
|
+
readonly voices: DisTubeVoiceManager;
|
|
15
|
+
readonly extractorPlugins: ExtractorPlugin[];
|
|
16
|
+
readonly customPlugins: CustomPlugin[];
|
|
17
|
+
readonly filters: Filters;
|
|
18
18
|
/**
|
|
19
19
|
* Create a new DisTube class.
|
|
20
20
|
* @param {Discord.Client} client Discord.JS client
|
|
@@ -30,33 +30,68 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
30
30
|
*/
|
|
31
31
|
constructor(client: Client, otp?: DisTubeOptions);
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* @param {Discord.
|
|
33
|
+
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
34
|
+
*
|
|
35
|
+
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
36
36
|
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
37
37
|
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
38
38
|
* @param {Object} [options] Optional options
|
|
39
39
|
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
40
40
|
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
41
41
|
* (after the playing song if exists)
|
|
42
|
+
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
43
|
+
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
44
|
+
* @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)
|
|
45
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
46
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
47
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
42
48
|
* @example
|
|
43
49
|
* client.on('message', (message) => {
|
|
44
50
|
* if (!message.content.startsWith(config.prefix)) return;
|
|
45
51
|
* const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
|
|
46
52
|
* const command = args.shift();
|
|
47
53
|
* if (command == "play")
|
|
48
|
-
* distube.play(message, args.join(" ")
|
|
54
|
+
* distube.play(message.member.voice?.channel, args.join(" "), {
|
|
55
|
+
* member: message.member,
|
|
56
|
+
* textChannel: message.channel,
|
|
57
|
+
* message
|
|
58
|
+
* });
|
|
49
59
|
* });
|
|
60
|
+
* @returns {Promise<void>}
|
|
50
61
|
*/
|
|
51
|
-
play(
|
|
62
|
+
play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist | null, options: {
|
|
52
63
|
skip?: boolean;
|
|
53
64
|
unshift?: boolean;
|
|
65
|
+
member?: GuildMember;
|
|
66
|
+
textChannel?: GuildTextBasedChannel;
|
|
67
|
+
message?: Message;
|
|
68
|
+
metadata?: any;
|
|
54
69
|
}): Promise<void>;
|
|
55
70
|
/**
|
|
56
71
|
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
57
|
-
*
|
|
72
|
+
*
|
|
73
|
+
* @param {Discord.Message} message A message from guild channel
|
|
74
|
+
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
75
|
+
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
76
|
+
* @param {Object} [options] Optional options
|
|
77
|
+
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
78
|
+
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
79
|
+
* (after the playing song if exists)
|
|
80
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
81
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
82
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
83
|
+
* @deprecated Message parameter is deprecated, use VoiceChannel instead. See {@link DisTube#play}
|
|
84
|
+
*/
|
|
85
|
+
play(message: Message<true>, song: string | Song | SearchResult | Playlist, options: {
|
|
86
|
+
skip?: boolean;
|
|
87
|
+
unshift?: boolean;
|
|
88
|
+
metadata?: any;
|
|
89
|
+
}): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
92
|
+
*
|
|
58
93
|
* @returns {Promise<void>}
|
|
59
|
-
* @param {Discord.
|
|
94
|
+
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
60
95
|
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
61
96
|
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
62
97
|
* @param {Object} [options] Optional options
|
|
@@ -64,21 +99,50 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
64
99
|
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
65
100
|
* (after the playing song if exists)
|
|
66
101
|
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
67
|
-
* @param {Discord.
|
|
102
|
+
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
68
103
|
* @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)
|
|
104
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
105
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
106
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
107
|
+
* @deprecated Use {@link DisTube#play} instead
|
|
69
108
|
*/
|
|
70
|
-
playVoiceChannel(voiceChannel:
|
|
109
|
+
playVoiceChannel(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist | null, options?: {
|
|
71
110
|
skip?: boolean;
|
|
72
111
|
unshift?: boolean;
|
|
73
112
|
member?: GuildMember;
|
|
74
|
-
textChannel?:
|
|
113
|
+
textChannel?: GuildTextBasedChannel;
|
|
75
114
|
message?: Message;
|
|
115
|
+
metadata?: any;
|
|
76
116
|
}): Promise<void>;
|
|
77
117
|
/**
|
|
78
|
-
*
|
|
118
|
+
* Create a custom playlist
|
|
119
|
+
* @returns {Promise<Playlist>}
|
|
120
|
+
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
121
|
+
* @param {Object} [options] Optional options
|
|
122
|
+
* @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
|
|
123
|
+
* @param {Object} [options.properties={}] Additional properties such as `name`
|
|
124
|
+
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
125
|
+
* @param {*} [options.metadata] Metadata
|
|
126
|
+
* @example
|
|
127
|
+
* const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
|
|
128
|
+
* const playlist = await distube.createCustomPlaylist(songs, {
|
|
129
|
+
* member: message.member,
|
|
130
|
+
* properties: { name: "My playlist name" },
|
|
131
|
+
* parallel: true
|
|
132
|
+
* });
|
|
133
|
+
* distube.play(voiceChannel, playlist, { ... });
|
|
134
|
+
*/
|
|
135
|
+
createCustomPlaylist(songs: (string | Song | SearchResult)[], options?: {
|
|
136
|
+
member?: GuildMember;
|
|
137
|
+
properties?: Record<string, any>;
|
|
138
|
+
parallel?: boolean;
|
|
139
|
+
metadata?: any;
|
|
140
|
+
}): Promise<Playlist>;
|
|
141
|
+
/**
|
|
142
|
+
* <info>Shorthand method of {@link DisTube#createCustomPlaylist} and {@link DisTube#play}
|
|
79
143
|
*
|
|
80
144
|
* If you doesn't have a user message (interaction,...),
|
|
81
|
-
* see {@link
|
|
145
|
+
* see {@link DisTube#createCustomPlaylist} example</info>
|
|
82
146
|
*
|
|
83
147
|
* Play or add array of video urls.
|
|
84
148
|
* {@link DisTube#event:playSong} or {@link DisTube#event:addList} will be emitted
|
|
@@ -87,27 +151,24 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
87
151
|
* @returns {Promise<void>}
|
|
88
152
|
* @param {Discord.Message} message A message from guild channel
|
|
89
153
|
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
90
|
-
* @param {Object} [properties={}] Additional properties such as `name`
|
|
154
|
+
* @param {Object} [properties={}] Additional properties for playlist such as `name`
|
|
91
155
|
* @param {Object} [options] Optional options
|
|
92
156
|
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
93
157
|
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
94
158
|
* (after the playing song if exists)
|
|
95
159
|
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
96
|
-
* @
|
|
97
|
-
* const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
|
|
98
|
-
* distube.playCustomPlaylist(message, songs, { name: "My playlist name" });
|
|
99
|
-
* // Fetching custom playlist sequentially (reduce lag for low specs)
|
|
100
|
-
* distube.playCustomPlaylist(message, songs, { name: "My playlist name" }, false, false);
|
|
160
|
+
* @deprecated Use {@link DisTube#createCustomPlaylist} and {@link DisTube#play} instead
|
|
101
161
|
*/
|
|
102
|
-
playCustomPlaylist(message: Message
|
|
162
|
+
playCustomPlaylist(message: Message<true>, songs: Array<string | Song | SearchResult>, properties?: Record<string, any>, options?: {
|
|
103
163
|
skip?: boolean;
|
|
104
164
|
unshift?: boolean;
|
|
105
165
|
parallel?: boolean;
|
|
166
|
+
metadata?: any;
|
|
106
167
|
}): Promise<void>;
|
|
107
168
|
/**
|
|
108
|
-
* Search for a song.
|
|
109
|
-
*
|
|
110
|
-
*
|
|
169
|
+
* Search for a song. You can customize how user answers instead of send a number.
|
|
170
|
+
* Then use {@link DisTube#play} to play it.
|
|
171
|
+
*
|
|
111
172
|
* @param {string} string The string search for
|
|
112
173
|
* @param {Object} options Search options
|
|
113
174
|
* @param {number} [options.limit=10] Limit the results
|
|
@@ -347,10 +408,10 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
347
408
|
/**
|
|
348
409
|
* Emit error event
|
|
349
410
|
* @param {Error} error error
|
|
350
|
-
* @param {Discord.
|
|
411
|
+
* @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
|
|
351
412
|
* @private
|
|
352
413
|
*/
|
|
353
|
-
emitError(error: Error, channel?:
|
|
414
|
+
emitError(error: Error, channel?: GuildTextBasedChannel): void;
|
|
354
415
|
}
|
|
355
416
|
export default DisTube;
|
|
356
417
|
/**
|
|
@@ -390,7 +451,7 @@ export default DisTube;
|
|
|
390
451
|
* Emitted when DisTube encounters an error.
|
|
391
452
|
*
|
|
392
453
|
* @event DisTube#error
|
|
393
|
-
* @param {Discord.
|
|
454
|
+
* @param {Discord.BaseGuildTextChannel} channel Text channel where the error is encountered.
|
|
394
455
|
* @param {Error} error The error encountered
|
|
395
456
|
* @example
|
|
396
457
|
* distube.on("error", (channel, error) => channel.send(
|
|
@@ -451,7 +512,7 @@ export default DisTube;
|
|
|
451
512
|
*/
|
|
452
513
|
/**
|
|
453
514
|
* Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
|
|
454
|
-
* and song param of {@link DisTube#
|
|
515
|
+
* and song param of {@link DisTube#play} is invalid url.
|
|
455
516
|
* DisTube will wait for user's next message to choose a song manually.
|
|
456
517
|
* <info>{@link https://support.google.com/youtube/answer/7354993|Safe search} is enabled
|
|
457
518
|
* if {@link DisTubeOptions}.nsfw is disabled and the message's channel is not a nsfw channel.</info>
|
package/dist/DisTube.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTube.d.ts","sourceRoot":"","sources":["../src/DisTube.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAEL,cAAc,EACd,mBAAmB,EAGnB,OAAO,EACP,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,YAAY,
|
|
1
|
+
{"version":3,"file":"DisTube.d.ts","sourceRoot":"","sources":["../src/DisTube.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAEL,cAAc,EACd,mBAAmB,EAGnB,OAAO,EACP,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,IAAI,EAQL,MA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_1 = require("./util");
|
|
10
10
|
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
11
11
|
const _1 = require(".");
|
|
12
|
+
// TODO: remove deprecated stuff on the next major version
|
|
12
13
|
/**
|
|
13
14
|
* DisTube class
|
|
14
15
|
* @extends EventEmitter
|
|
@@ -83,70 +84,40 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
83
84
|
*/
|
|
84
85
|
this.customPlugins = this.options.plugins.filter((p) => p.type === "custom");
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
async play(voiceChannel, song, options = {}) {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if ((0, _1.isMessageInstance)(voiceChannel)) {
|
|
90
|
+
process.emitWarning("Passing Message for DisTube#play is deprecated, use VoiceBasedChannel instead.", "DeprecationWarning");
|
|
91
|
+
const message = voiceChannel;
|
|
92
|
+
if (!song)
|
|
93
|
+
throw new _1.DisTubeError("INVALID_TYPE", ["string", "Song", "SearchResult", "Playlist"], song, "song");
|
|
94
|
+
if (!(0, _1.isMessageInstance)(message))
|
|
95
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Discord.Message", message, "message");
|
|
96
|
+
if (typeof options !== "object" || Array.isArray(options)) {
|
|
97
|
+
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
98
|
+
}
|
|
99
|
+
const textChannel = message.channel;
|
|
100
|
+
const { skip, unshift, metadata } = Object.assign({ skip: false, unshift: false }, options);
|
|
101
|
+
const member = message.member;
|
|
102
|
+
const vc = member.voice.channel;
|
|
103
|
+
if (!vc)
|
|
104
|
+
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
105
|
+
return this.play(vc, song, {
|
|
106
|
+
member,
|
|
107
|
+
textChannel,
|
|
108
|
+
skip,
|
|
109
|
+
message,
|
|
110
|
+
unshift,
|
|
111
|
+
metadata,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!(0, _1.isSupportedVoiceChannel)(voiceChannel)) {
|
|
115
|
+
throw new _1.DisTubeError("INVALID_TYPE", "BaseGuildVoiceChannel", voiceChannel, "voiceChannel");
|
|
112
116
|
}
|
|
113
|
-
const textChannel = message.channel;
|
|
114
|
-
const { skip, unshift } = Object.assign({ skip: false, unshift: false }, options);
|
|
115
|
-
const member = message.member;
|
|
116
|
-
const voiceChannel = member.voice.channel;
|
|
117
|
-
if (!voiceChannel)
|
|
118
|
-
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
119
|
-
await this.playVoiceChannel(voiceChannel, song, {
|
|
120
|
-
member,
|
|
121
|
-
textChannel,
|
|
122
|
-
skip,
|
|
123
|
-
message,
|
|
124
|
-
unshift,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
129
|
-
* Emit {@link DisTube#addList}, {@link DisTube#addSong} or {@link DisTube#playSong} after executing
|
|
130
|
-
* @returns {Promise<void>}
|
|
131
|
-
* @param {Discord.VoiceChannel|Discord.StageChannel} voiceChannel The voice channel will be joined
|
|
132
|
-
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
133
|
-
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
134
|
-
* @param {Object} [options] Optional options
|
|
135
|
-
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
136
|
-
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
137
|
-
* (after the playing song if exists)
|
|
138
|
-
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
139
|
-
* @param {Discord.TextChannel} [options.textChannel] Default {@link Queue#textChannel} (if the queue wasn't created)
|
|
140
|
-
* @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)
|
|
141
|
-
*/
|
|
142
|
-
async playVoiceChannel(voiceChannel, song, options = {}) {
|
|
143
|
-
var _a;
|
|
144
|
-
if (!(0, _1.isSupportedVoiceChannel)(voiceChannel))
|
|
145
|
-
throw new _1.DisTubeError("NOT_SUPPORTED_VOICE");
|
|
146
117
|
if (typeof options !== "object" || Array.isArray(options)) {
|
|
147
118
|
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
148
119
|
}
|
|
149
|
-
const { textChannel, member, skip, message, unshift } = Object.assign({
|
|
120
|
+
const { textChannel, member, skip, message, unshift, metadata } = Object.assign({
|
|
150
121
|
member: voiceChannel.guild.me,
|
|
151
122
|
skip: false,
|
|
152
123
|
unshift: false,
|
|
@@ -158,32 +129,33 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
158
129
|
if (typeof song === "string") {
|
|
159
130
|
for (const plugin of this.customPlugins) {
|
|
160
131
|
if (await plugin.validate(song)) {
|
|
161
|
-
return plugin.play(voiceChannel, song,
|
|
132
|
+
return plugin.play(voiceChannel, song, options);
|
|
162
133
|
}
|
|
163
134
|
}
|
|
164
135
|
}
|
|
165
136
|
let queue = this.getQueue(voiceChannel);
|
|
166
|
-
const queuing = queue && !queue.taskQueue.hasResolveTask;
|
|
137
|
+
const queuing = !!queue && !queue.taskQueue.hasResolveTask;
|
|
167
138
|
if (queuing)
|
|
168
139
|
await (queue === null || queue === void 0 ? void 0 : queue.taskQueue.queuing(true));
|
|
169
140
|
try {
|
|
170
141
|
if (song instanceof _1.SearchResult && song.type === "playlist")
|
|
171
142
|
song = song.url;
|
|
172
|
-
if (typeof song === "string" && ytpl_1.default.validateID(song))
|
|
173
|
-
song = await this.handler.resolvePlaylist(member,
|
|
143
|
+
if (typeof song === "string" && ytpl_1.default.validateID(song)) {
|
|
144
|
+
song = await this.handler.resolvePlaylist(song, { member, metadata });
|
|
145
|
+
}
|
|
174
146
|
if (typeof song === "string" && !(0, util_1.isURL)(song)) {
|
|
175
147
|
if (!message)
|
|
176
148
|
song = (await this.search(song, { limit: 1 }))[0];
|
|
177
149
|
else
|
|
178
150
|
song = await this.handler.searchSong(message, song);
|
|
179
151
|
}
|
|
180
|
-
song = await this.handler.resolveSong(member,
|
|
152
|
+
song = await this.handler.resolveSong(song, { member, metadata });
|
|
181
153
|
if (!song)
|
|
182
154
|
return;
|
|
183
155
|
if (song instanceof _1.Playlist) {
|
|
184
|
-
await this.handler.handlePlaylist(voiceChannel, song, textChannel, skip, unshift);
|
|
156
|
+
await this.handler.handlePlaylist(voiceChannel, song, { textChannel, skip, unshift });
|
|
185
157
|
}
|
|
186
|
-
else if (!this.options.nsfw && song.age_restricted && !(textChannel === null ||
|
|
158
|
+
else if (!this.options.nsfw && song.age_restricted && !((_a = textChannel) === null || _a === void 0 ? void 0 : _a.nsfw)) {
|
|
187
159
|
throw new _1.DisTubeError("NON_NSFW");
|
|
188
160
|
}
|
|
189
161
|
else {
|
|
@@ -196,7 +168,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
196
168
|
this.emit("addSong", queue, song);
|
|
197
169
|
}
|
|
198
170
|
else {
|
|
199
|
-
const newQueue = await this.
|
|
171
|
+
const newQueue = await this.queues.create(voiceChannel, song, textChannel);
|
|
200
172
|
if (newQueue instanceof _1.Queue) {
|
|
201
173
|
if (this.options.emitAddSongWhenCreatingQueue)
|
|
202
174
|
this.emit("addSong", newQueue, song);
|
|
@@ -214,7 +186,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
214
186
|
if (!(e instanceof _1.DisTubeError)) {
|
|
215
187
|
try {
|
|
216
188
|
e.name = "PlayError";
|
|
217
|
-
e.message = `${((
|
|
189
|
+
e.message = `${((_b = song) === null || _b === void 0 ? void 0 : _b.url) || song}\n${e.message}`;
|
|
218
190
|
}
|
|
219
191
|
catch { }
|
|
220
192
|
}
|
|
@@ -222,10 +194,79 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
222
194
|
}
|
|
223
195
|
}
|
|
224
196
|
/**
|
|
225
|
-
*
|
|
197
|
+
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
198
|
+
*
|
|
199
|
+
* @returns {Promise<void>}
|
|
200
|
+
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
201
|
+
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
202
|
+
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
203
|
+
* @param {Object} [options] Optional options
|
|
204
|
+
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
205
|
+
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
206
|
+
* (after the playing song if exists)
|
|
207
|
+
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
208
|
+
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
209
|
+
* @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)
|
|
210
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
211
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
212
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
213
|
+
* @deprecated Use {@link DisTube#play} instead
|
|
214
|
+
*/
|
|
215
|
+
async playVoiceChannel(voiceChannel, song, options = {}) {
|
|
216
|
+
process.emitWarning("DisTube#playVoiceChannel is deprecated, use DisTube#play instead.", "DeprecationWarning");
|
|
217
|
+
return this.play(voiceChannel, song, options);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Create a custom playlist
|
|
221
|
+
* @returns {Promise<Playlist>}
|
|
222
|
+
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
223
|
+
* @param {Object} [options] Optional options
|
|
224
|
+
* @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
|
|
225
|
+
* @param {Object} [options.properties={}] Additional properties such as `name`
|
|
226
|
+
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
227
|
+
* @param {*} [options.metadata] Metadata
|
|
228
|
+
* @example
|
|
229
|
+
* const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
|
|
230
|
+
* const playlist = await distube.createCustomPlaylist(songs, {
|
|
231
|
+
* member: message.member,
|
|
232
|
+
* properties: { name: "My playlist name" },
|
|
233
|
+
* parallel: true
|
|
234
|
+
* });
|
|
235
|
+
* distube.play(voiceChannel, playlist, { ... });
|
|
236
|
+
*/
|
|
237
|
+
async createCustomPlaylist(songs, options = {}) {
|
|
238
|
+
const { member, properties, parallel, metadata } = Object.assign({ parallel: true }, options);
|
|
239
|
+
if (!Array.isArray(songs))
|
|
240
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Array", songs, "songs");
|
|
241
|
+
if (!songs.length)
|
|
242
|
+
throw new _1.DisTubeError("EMPTY_ARRAY", "songs");
|
|
243
|
+
const filteredSongs = songs.filter(song => song instanceof _1.Song || (song instanceof _1.SearchResult && song.type === "video") || (0, util_1.isURL)(song));
|
|
244
|
+
if (!filteredSongs.length)
|
|
245
|
+
throw new _1.DisTubeError("NO_VALID_SONG");
|
|
246
|
+
if (member && !(0, _1.isMemberInstance)(member)) {
|
|
247
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Discord.Member", member, "options.member");
|
|
248
|
+
}
|
|
249
|
+
if (!filteredSongs.length)
|
|
250
|
+
throw new _1.DisTubeError("NO_VALID_SONG");
|
|
251
|
+
let resolvedSongs;
|
|
252
|
+
if (parallel) {
|
|
253
|
+
const promises = filteredSongs.map((song) => this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
|
|
254
|
+
resolvedSongs = (await Promise.all(promises)).filter((s) => !!s);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
const resolved = [];
|
|
258
|
+
for (const song of filteredSongs) {
|
|
259
|
+
resolved.push(await this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
|
|
260
|
+
}
|
|
261
|
+
resolvedSongs = resolved.filter((s) => !!s);
|
|
262
|
+
}
|
|
263
|
+
return new _1.Playlist(resolvedSongs, { member, properties, metadata });
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* <info>Shorthand method of {@link DisTube#createCustomPlaylist} and {@link DisTube#play}
|
|
226
267
|
*
|
|
227
268
|
* If you doesn't have a user message (interaction,...),
|
|
228
|
-
* see {@link
|
|
269
|
+
* see {@link DisTube#createCustomPlaylist} example</info>
|
|
229
270
|
*
|
|
230
271
|
* Play or add array of video urls.
|
|
231
272
|
* {@link DisTube#event:playSong} or {@link DisTube#event:addList} will be emitted
|
|
@@ -234,24 +275,22 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
234
275
|
* @returns {Promise<void>}
|
|
235
276
|
* @param {Discord.Message} message A message from guild channel
|
|
236
277
|
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
237
|
-
* @param {Object} [properties={}] Additional properties such as `name`
|
|
278
|
+
* @param {Object} [properties={}] Additional properties for playlist such as `name`
|
|
238
279
|
* @param {Object} [options] Optional options
|
|
239
280
|
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
240
281
|
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
241
282
|
* (after the playing song if exists)
|
|
242
283
|
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
243
|
-
* @
|
|
244
|
-
* const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
|
|
245
|
-
* distube.playCustomPlaylist(message, songs, { name: "My playlist name" });
|
|
246
|
-
* // Fetching custom playlist sequentially (reduce lag for low specs)
|
|
247
|
-
* distube.playCustomPlaylist(message, songs, { name: "My playlist name" }, false, false);
|
|
284
|
+
* @deprecated Use {@link DisTube#createCustomPlaylist} and {@link DisTube#play} instead
|
|
248
285
|
*/
|
|
249
286
|
async playCustomPlaylist(message, songs, properties = {}, options = {}) {
|
|
287
|
+
var _a, _b, _c;
|
|
288
|
+
process.emitWarning("DisTube#playCustomPlaylist is deprecated, use DisTube#createCustomPlaylist and DisTube#play instead.", "DeprecationWarning");
|
|
250
289
|
try {
|
|
251
290
|
if (typeof options !== "object" || Array.isArray(options)) {
|
|
252
291
|
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
253
292
|
}
|
|
254
|
-
const { skip, unshift, parallel } = Object.assign({
|
|
293
|
+
const { skip, unshift, parallel, metadata } = Object.assign({
|
|
255
294
|
skip: false,
|
|
256
295
|
unshift: false,
|
|
257
296
|
parallel: true,
|
|
@@ -261,8 +300,16 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
261
300
|
if (queuing)
|
|
262
301
|
await (queue === null || queue === void 0 ? void 0 : queue.taskQueue.queuing(true));
|
|
263
302
|
try {
|
|
264
|
-
const playlist = await this.
|
|
265
|
-
|
|
303
|
+
const playlist = await this.createCustomPlaylist(songs, {
|
|
304
|
+
member: (_a = message.member) !== null && _a !== void 0 ? _a : undefined,
|
|
305
|
+
properties,
|
|
306
|
+
parallel,
|
|
307
|
+
metadata,
|
|
308
|
+
});
|
|
309
|
+
const voice = (_c = (_b = message.member) === null || _b === void 0 ? void 0 : _b.voice) === null || _c === void 0 ? void 0 : _c.channel;
|
|
310
|
+
if (!voice)
|
|
311
|
+
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
312
|
+
await this.play(voice, playlist, { textChannel: message.channel, skip, unshift, metadata });
|
|
266
313
|
}
|
|
267
314
|
finally {
|
|
268
315
|
if (queuing)
|
|
@@ -274,9 +321,9 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
274
321
|
}
|
|
275
322
|
}
|
|
276
323
|
/**
|
|
277
|
-
* Search for a song.
|
|
278
|
-
*
|
|
279
|
-
*
|
|
324
|
+
* Search for a song. You can customize how user answers instead of send a number.
|
|
325
|
+
* Then use {@link DisTube#play} to play it.
|
|
326
|
+
*
|
|
280
327
|
* @param {string} string The string search for
|
|
281
328
|
* @param {Object} options Search options
|
|
282
329
|
* @param {number} [options.limit=10] Limit the results
|
|
@@ -605,7 +652,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
605
652
|
/**
|
|
606
653
|
* Emit error event
|
|
607
654
|
* @param {Error} error error
|
|
608
|
-
* @param {Discord.
|
|
655
|
+
* @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
|
|
609
656
|
* @private
|
|
610
657
|
*/
|
|
611
658
|
emitError(error, channel) {
|
|
@@ -662,7 +709,7 @@ exports.default = DisTube;
|
|
|
662
709
|
* Emitted when DisTube encounters an error.
|
|
663
710
|
*
|
|
664
711
|
* @event DisTube#error
|
|
665
|
-
* @param {Discord.
|
|
712
|
+
* @param {Discord.BaseGuildTextChannel} channel Text channel where the error is encountered.
|
|
666
713
|
* @param {Error} error The error encountered
|
|
667
714
|
* @example
|
|
668
715
|
* distube.on("error", (channel, error) => channel.send(
|
|
@@ -723,7 +770,7 @@ exports.default = DisTube;
|
|
|
723
770
|
*/
|
|
724
771
|
/**
|
|
725
772
|
* Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
|
|
726
|
-
* and song param of {@link DisTube#
|
|
773
|
+
* and song param of {@link DisTube#play} is invalid url.
|
|
727
774
|
* DisTube will wait for user's next message to choose a song manually.
|
|
728
775
|
* <info>{@link https://support.google.com/youtube/answer/7354993|Safe search} is enabled
|
|
729
776
|
* if {@link DisTubeOptions}.nsfw is disabled and the message's channel is not a nsfw channel.</info>
|