distube 3.0.4 → 3.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/README.md +6 -6
- package/dist/DisTube.d.ts +98 -37
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +130 -84
- 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 +68 -59
- 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 +37 -29
- 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 -2
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +4 -3
- 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 +6 -7
- 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 +39 -27
- 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 +6 -4
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +27 -2
- package/dist/util.js.map +1 -1
- package/package.json +26 -20
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,39 @@ 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
|
+
});
|
|
112
113
|
}
|
|
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
114
|
if (!(0, _1.isSupportedVoiceChannel)(voiceChannel))
|
|
145
115
|
throw new _1.DisTubeError("NOT_SUPPORTED_VOICE");
|
|
146
116
|
if (typeof options !== "object" || Array.isArray(options)) {
|
|
147
117
|
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
148
118
|
}
|
|
149
|
-
const { textChannel, member, skip, message, unshift } = Object.assign({
|
|
119
|
+
const { textChannel, member, skip, message, unshift, metadata } = Object.assign({
|
|
150
120
|
member: voiceChannel.guild.me,
|
|
151
121
|
skip: false,
|
|
152
122
|
unshift: false,
|
|
@@ -158,32 +128,33 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
158
128
|
if (typeof song === "string") {
|
|
159
129
|
for (const plugin of this.customPlugins) {
|
|
160
130
|
if (await plugin.validate(song)) {
|
|
161
|
-
return plugin.play(voiceChannel, song,
|
|
131
|
+
return plugin.play(voiceChannel, song, options);
|
|
162
132
|
}
|
|
163
133
|
}
|
|
164
134
|
}
|
|
165
135
|
let queue = this.getQueue(voiceChannel);
|
|
166
|
-
const queuing = queue && !queue.taskQueue.hasResolveTask;
|
|
136
|
+
const queuing = !!queue && !queue.taskQueue.hasResolveTask;
|
|
167
137
|
if (queuing)
|
|
168
138
|
await (queue === null || queue === void 0 ? void 0 : queue.taskQueue.queuing(true));
|
|
169
139
|
try {
|
|
170
140
|
if (song instanceof _1.SearchResult && song.type === "playlist")
|
|
171
141
|
song = song.url;
|
|
172
|
-
if (typeof song === "string" && ytpl_1.default.validateID(song))
|
|
173
|
-
song = await this.handler.resolvePlaylist(member,
|
|
142
|
+
if (typeof song === "string" && ytpl_1.default.validateID(song)) {
|
|
143
|
+
song = await this.handler.resolvePlaylist(song, { member, metadata });
|
|
144
|
+
}
|
|
174
145
|
if (typeof song === "string" && !(0, util_1.isURL)(song)) {
|
|
175
146
|
if (!message)
|
|
176
147
|
song = (await this.search(song, { limit: 1 }))[0];
|
|
177
148
|
else
|
|
178
149
|
song = await this.handler.searchSong(message, song);
|
|
179
150
|
}
|
|
180
|
-
song = await this.handler.resolveSong(member,
|
|
151
|
+
song = await this.handler.resolveSong(song, { member, metadata });
|
|
181
152
|
if (!song)
|
|
182
153
|
return;
|
|
183
154
|
if (song instanceof _1.Playlist) {
|
|
184
|
-
await this.handler.handlePlaylist(voiceChannel, song, textChannel, skip, unshift);
|
|
155
|
+
await this.handler.handlePlaylist(voiceChannel, song, { textChannel, skip, unshift });
|
|
185
156
|
}
|
|
186
|
-
else if (!this.options.nsfw && song.age_restricted && !(textChannel === null ||
|
|
157
|
+
else if (!this.options.nsfw && song.age_restricted && !((_a = textChannel) === null || _a === void 0 ? void 0 : _a.nsfw)) {
|
|
187
158
|
throw new _1.DisTubeError("NON_NSFW");
|
|
188
159
|
}
|
|
189
160
|
else {
|
|
@@ -196,7 +167,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
196
167
|
this.emit("addSong", queue, song);
|
|
197
168
|
}
|
|
198
169
|
else {
|
|
199
|
-
const newQueue = await this.
|
|
170
|
+
const newQueue = await this.queues.create(voiceChannel, song, textChannel);
|
|
200
171
|
if (newQueue instanceof _1.Queue) {
|
|
201
172
|
if (this.options.emitAddSongWhenCreatingQueue)
|
|
202
173
|
this.emit("addSong", newQueue, song);
|
|
@@ -214,7 +185,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
214
185
|
if (!(e instanceof _1.DisTubeError)) {
|
|
215
186
|
try {
|
|
216
187
|
e.name = "PlayError";
|
|
217
|
-
e.message = `${((
|
|
188
|
+
e.message = `${((_b = song) === null || _b === void 0 ? void 0 : _b.url) || song}\n${e.message}`;
|
|
218
189
|
}
|
|
219
190
|
catch { }
|
|
220
191
|
}
|
|
@@ -222,10 +193,79 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
222
193
|
}
|
|
223
194
|
}
|
|
224
195
|
/**
|
|
225
|
-
*
|
|
196
|
+
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
197
|
+
*
|
|
198
|
+
* @returns {Promise<void>}
|
|
199
|
+
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
200
|
+
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
201
|
+
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
202
|
+
* @param {Object} [options] Optional options
|
|
203
|
+
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
204
|
+
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
205
|
+
* (after the playing song if exists)
|
|
206
|
+
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
207
|
+
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
208
|
+
* @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)
|
|
209
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
210
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
211
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
212
|
+
* @deprecated Use {@link DisTube#play} instead
|
|
213
|
+
*/
|
|
214
|
+
async playVoiceChannel(voiceChannel, song, options = {}) {
|
|
215
|
+
process.emitWarning("DisTube#playVoiceChannel is deprecated, use DisTube#play instead.", "DeprecationWarning");
|
|
216
|
+
return this.play(voiceChannel, song, options);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Create a custom playlist
|
|
220
|
+
* @returns {Promise<Playlist>}
|
|
221
|
+
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
222
|
+
* @param {Object} [options] Optional options
|
|
223
|
+
* @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
|
|
224
|
+
* @param {Object} [options.properties={}] Additional properties such as `name`
|
|
225
|
+
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
226
|
+
* @param {*} [options.metadata] Metadata
|
|
227
|
+
* @example
|
|
228
|
+
* const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
|
|
229
|
+
* const playlist = await distube.createCustomPlaylist(songs, {
|
|
230
|
+
* member: message.member,
|
|
231
|
+
* properties: { name: "My playlist name" },
|
|
232
|
+
* parallel: true
|
|
233
|
+
* });
|
|
234
|
+
* distube.play(voiceChannel, playlist, { ... });
|
|
235
|
+
*/
|
|
236
|
+
async createCustomPlaylist(songs, options = {}) {
|
|
237
|
+
const { member, properties, parallel, metadata } = Object.assign({ parallel: true }, options);
|
|
238
|
+
if (!Array.isArray(songs))
|
|
239
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Array", songs, "songs");
|
|
240
|
+
if (!songs.length)
|
|
241
|
+
throw new _1.DisTubeError("EMPTY_ARRAY", "songs");
|
|
242
|
+
const filteredSongs = songs.filter(song => song instanceof _1.Song || (song instanceof _1.SearchResult && song.type === "video") || (0, util_1.isURL)(song));
|
|
243
|
+
if (!filteredSongs.length)
|
|
244
|
+
throw new _1.DisTubeError("NO_VALID_SONG");
|
|
245
|
+
if (member && !(0, _1.isMemberInstance)(member)) {
|
|
246
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Discord.Member", member, "options.member");
|
|
247
|
+
}
|
|
248
|
+
if (!filteredSongs.length)
|
|
249
|
+
throw new _1.DisTubeError("NO_VALID_SONG");
|
|
250
|
+
let resolvedSongs;
|
|
251
|
+
if (parallel) {
|
|
252
|
+
const promises = filteredSongs.map((song) => this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
|
|
253
|
+
resolvedSongs = (await Promise.all(promises)).filter((s) => !!s);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
const resolved = [];
|
|
257
|
+
for (const song of filteredSongs) {
|
|
258
|
+
resolved.push(await this.handler.resolveSong(song, { member, metadata }).catch(() => undefined));
|
|
259
|
+
}
|
|
260
|
+
resolvedSongs = resolved.filter((s) => !!s);
|
|
261
|
+
}
|
|
262
|
+
return new _1.Playlist(resolvedSongs, { member, properties, metadata });
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* <info>Shorthand method of {@link DisTube#createCustomPlaylist} and {@link DisTube#play}
|
|
226
266
|
*
|
|
227
267
|
* If you doesn't have a user message (interaction,...),
|
|
228
|
-
* see {@link
|
|
268
|
+
* see {@link DisTube#createCustomPlaylist} example</info>
|
|
229
269
|
*
|
|
230
270
|
* Play or add array of video urls.
|
|
231
271
|
* {@link DisTube#event:playSong} or {@link DisTube#event:addList} will be emitted
|
|
@@ -234,24 +274,22 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
234
274
|
* @returns {Promise<void>}
|
|
235
275
|
* @param {Discord.Message} message A message from guild channel
|
|
236
276
|
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
237
|
-
* @param {Object} [properties={}] Additional properties such as `name`
|
|
277
|
+
* @param {Object} [properties={}] Additional properties for playlist such as `name`
|
|
238
278
|
* @param {Object} [options] Optional options
|
|
239
279
|
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
240
280
|
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
241
281
|
* (after the playing song if exists)
|
|
242
282
|
* @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);
|
|
283
|
+
* @deprecated Use {@link DisTube#createCustomPlaylist} and {@link DisTube#play} instead
|
|
248
284
|
*/
|
|
249
285
|
async playCustomPlaylist(message, songs, properties = {}, options = {}) {
|
|
286
|
+
var _a, _b, _c;
|
|
287
|
+
process.emitWarning("DisTube#playCustomPlaylist is deprecated, use DisTube#createCustomPlaylist and DisTube#play instead.", "DeprecationWarning");
|
|
250
288
|
try {
|
|
251
289
|
if (typeof options !== "object" || Array.isArray(options)) {
|
|
252
290
|
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
253
291
|
}
|
|
254
|
-
const { skip, unshift, parallel } = Object.assign({
|
|
292
|
+
const { skip, unshift, parallel, metadata } = Object.assign({
|
|
255
293
|
skip: false,
|
|
256
294
|
unshift: false,
|
|
257
295
|
parallel: true,
|
|
@@ -261,8 +299,16 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
261
299
|
if (queuing)
|
|
262
300
|
await (queue === null || queue === void 0 ? void 0 : queue.taskQueue.queuing(true));
|
|
263
301
|
try {
|
|
264
|
-
const playlist = await this.
|
|
265
|
-
|
|
302
|
+
const playlist = await this.createCustomPlaylist(songs, {
|
|
303
|
+
member: (_a = message.member) !== null && _a !== void 0 ? _a : undefined,
|
|
304
|
+
properties,
|
|
305
|
+
parallel,
|
|
306
|
+
metadata,
|
|
307
|
+
});
|
|
308
|
+
const voice = (_c = (_b = message.member) === null || _b === void 0 ? void 0 : _b.voice) === null || _c === void 0 ? void 0 : _c.channel;
|
|
309
|
+
if (!voice)
|
|
310
|
+
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
311
|
+
await this.play(voice, playlist, { textChannel: message.channel, skip, unshift, metadata });
|
|
266
312
|
}
|
|
267
313
|
finally {
|
|
268
314
|
if (queuing)
|
|
@@ -274,9 +320,9 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
274
320
|
}
|
|
275
321
|
}
|
|
276
322
|
/**
|
|
277
|
-
* Search for a song.
|
|
278
|
-
*
|
|
279
|
-
*
|
|
323
|
+
* Search for a song. You can customize how user answers instead of send a number.
|
|
324
|
+
* Then use {@link DisTube#play} to play it.
|
|
325
|
+
*
|
|
280
326
|
* @param {string} string The string search for
|
|
281
327
|
* @param {Object} options Search options
|
|
282
328
|
* @param {number} [options.limit=10] Limit the results
|
|
@@ -605,7 +651,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
605
651
|
/**
|
|
606
652
|
* Emit error event
|
|
607
653
|
* @param {Error} error error
|
|
608
|
-
* @param {Discord.
|
|
654
|
+
* @param {Discord.BaseGuildTextChannel} [channel] Text channel where the error is encountered.
|
|
609
655
|
* @private
|
|
610
656
|
*/
|
|
611
657
|
emitError(error, channel) {
|
|
@@ -662,7 +708,7 @@ exports.default = DisTube;
|
|
|
662
708
|
* Emitted when DisTube encounters an error.
|
|
663
709
|
*
|
|
664
710
|
* @event DisTube#error
|
|
665
|
-
* @param {Discord.
|
|
711
|
+
* @param {Discord.BaseGuildTextChannel} channel Text channel where the error is encountered.
|
|
666
712
|
* @param {Error} error The error encountered
|
|
667
713
|
* @example
|
|
668
714
|
* distube.on("error", (channel, error) => channel.send(
|
|
@@ -723,7 +769,7 @@ exports.default = DisTube;
|
|
|
723
769
|
*/
|
|
724
770
|
/**
|
|
725
771
|
* Emitted when {@link DisTubeOptions|DisTubeOptions.searchSongs} bigger than 0,
|
|
726
|
-
* and song param of {@link DisTube#
|
|
772
|
+
* and song param of {@link DisTube#play} is invalid url.
|
|
727
773
|
* DisTube will wait for user's next message to choose a song manually.
|
|
728
774
|
* <info>{@link https://support.google.com/youtube/answer/7354993|Safe search} is enabled
|
|
729
775
|
* if {@link DisTubeOptions}.nsfw is disabled and the message's channel is not a nsfw channel.</info>
|