distube 3.3.0 → 4.0.0-dev.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 -8
- package/dist/DisTube.d.ts +2 -79
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +58 -144
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +0 -5
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +0 -5
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +3 -24
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +19 -67
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeOptions.d.ts +1 -3
- package/dist/core/DisTubeOptions.d.ts.map +1 -1
- package/dist/core/DisTubeOptions.js +3 -17
- 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.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +1 -3
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/index.d.ts +0 -1
- package/dist/core/voice/index.d.ts.map +1 -1
- package/dist/core/voice/index.js +0 -1
- package/dist/core/voice/index.js.map +1 -1
- package/dist/plugin/index.d.ts +0 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +0 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/struct/CustomPlugin.d.ts +32 -26
- package/dist/struct/CustomPlugin.d.ts.map +1 -1
- package/dist/struct/CustomPlugin.js +32 -24
- package/dist/struct/CustomPlugin.js.map +1 -1
- package/dist/struct/DisTubeError.d.ts +1 -2
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +1 -3
- package/dist/struct/DisTubeError.js.map +1 -1
- package/dist/struct/ExtractorPlugin.d.ts +21 -15
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
- package/dist/struct/ExtractorPlugin.js +21 -12
- package/dist/struct/ExtractorPlugin.js.map +1 -1
- package/dist/struct/Playlist.d.ts +11 -15
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +54 -40
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Plugin.d.ts +5 -11
- package/dist/struct/Plugin.d.ts.map +1 -1
- package/dist/struct/Plugin.js +4 -12
- package/dist/struct/Plugin.js.map +1 -1
- package/dist/struct/Song.d.ts +15 -21
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +54 -44
- package/dist/struct/Song.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +1 -6
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +2 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +25 -29
- package/dist/util.js.map +1 -1
- package/package.json +14 -15
- package/dist/core/voice/DJSAdapter.d.ts +0 -4
- package/dist/core/voice/DJSAdapter.d.ts.map +0 -1
- package/dist/core/voice/DJSAdapter.js +0 -58
- package/dist/core/voice/DJSAdapter.js.map +0 -1
- package/dist/plugin/youtube-dl.d.ts +0 -12
- package/dist/plugin/youtube-dl.d.ts.map +0 -1
- package/dist/plugin/youtube-dl.js +0 -70
- package/dist/plugin/youtube-dl.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<img alt="node-current" src="https://img.shields.io/node/v/distube?logo=node.js&logoColor=white&style=flat-square">
|
|
8
8
|
<img alt="npm peer dependency version" src="https://img.shields.io/npm/dependency-version/distube/peer/discord.js?label=discord.js&logo=discord&logoColor=white&style=flat-square">
|
|
9
9
|
<img alt="Depfu" src="https://img.shields.io/depfu/skick1234/DisTube?style=flat-square">
|
|
10
|
-
<img alt="Codecov branch" src="https://img.shields.io/codecov/c/github/skick1234/DisTube?logo=codecov&logoColor=white&style=flat-square&token=WWDYRRSEQW">
|
|
10
|
+
<img alt="Codecov branch" src="https://img.shields.io/codecov/c/github/skick1234/DisTube/main?logo=codecov&logoColor=white&style=flat-square&token=WWDYRRSEQW">
|
|
11
11
|
<br>
|
|
12
12
|
<img alt="npm" src="https://img.shields.io/npm/dt/distube?logo=npm&style=flat-square">
|
|
13
13
|
<img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/skick1234/DisTube?logo=github&logoColor=white&style=flat-square">
|
|
@@ -25,25 +25,24 @@ A Discord.js module to simplify your music commands and play songs with audio fi
|
|
|
25
25
|
|
|
26
26
|
- Build on `@discordjs/voice`
|
|
27
27
|
- Easy to use and customize
|
|
28
|
-
- Support YouTube
|
|
28
|
+
- Support YouTube and audio link
|
|
29
29
|
- Audio filters (bassboost, nightcore, vaporwave,...)
|
|
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
|
-
|
|
33
|
+
## Requirement
|
|
34
34
|
|
|
35
|
-
- Node
|
|
36
|
-
- [discord.js](https://discord.js.org)
|
|
35
|
+
- Node.js 16.9.0 or higher
|
|
36
|
+
- [discord.js](https://discord.js.org) v14
|
|
37
37
|
- [@discordjs/voice](https://github.com/discordjs/voice)
|
|
38
38
|
- [FFmpeg](https://www.ffmpeg.org/download.html)
|
|
39
39
|
- [@discordjs/opus](https://github.com/discordjs/opus)
|
|
40
40
|
- [sodium](https://www.npmjs.com/package/sodium) or [libsodium-wrappers](https://www.npmjs.com/package/libsodium-wrappers)
|
|
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).)_
|
|
42
41
|
|
|
43
42
|
## Installation
|
|
44
43
|
|
|
45
44
|
```npm
|
|
46
|
-
npm install distube@
|
|
45
|
+
npm install distube@dev
|
|
47
46
|
```
|
|
48
47
|
|
|
49
48
|
## Documentation
|
|
@@ -61,4 +60,3 @@ Read DisTube's definitions, properties and events details in the [Documentation
|
|
|
61
60
|
- [node-ytdl-core](https://github.com/fent/node-ytdl-core): YouTube scraper ([DisTube Fork](https://github.com/distubejs/node-ytdl-core))
|
|
62
61
|
- [node-ytsr](https://github.com/TimeForANinja/node-ytsr): YouTube search scraper ([DisTube Fork](https://github.com/distubejs/ytsr))
|
|
63
62
|
- [node-ytpl](https://github.com/TimeForANinja/node-ytpl): YouTube playlist resolver ([DisTube Fork](https://github.com/distubejs/ytpl))
|
|
64
|
-
- [youtube-dl-exec](https://github.com/microlinkhq/youtube-dl-exec): [`youtube-dl`](https://youtube-dl.org/) wrapper
|
package/dist/DisTube.d.ts
CHANGED
|
@@ -70,55 +70,7 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
70
70
|
* });
|
|
71
71
|
* @returns {Promise<void>}
|
|
72
72
|
*/
|
|
73
|
-
play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist
|
|
74
|
-
skip?: boolean;
|
|
75
|
-
position?: number;
|
|
76
|
-
member?: GuildMember;
|
|
77
|
-
textChannel?: GuildTextBasedChannel;
|
|
78
|
-
message?: Message;
|
|
79
|
-
metadata?: any;
|
|
80
|
-
}): Promise<void>;
|
|
81
|
-
/** @deprecated Message parameter is deprecated, use VoiceChannel instead. */
|
|
82
|
-
play(message: Message<true>, song: string | Song | SearchResult | Playlist, options?: {
|
|
83
|
-
skip?: boolean;
|
|
84
|
-
unshift?: boolean;
|
|
85
|
-
metadata?: any;
|
|
86
|
-
}): Promise<void>;
|
|
87
|
-
/** @deprecated `options.unshift` is deprecated, use `options.position` instead */
|
|
88
|
-
play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist | null, options?: {
|
|
89
|
-
skip?: boolean;
|
|
90
|
-
/** @deprecated Use `options.position` instead */
|
|
91
|
-
unshift?: boolean;
|
|
92
|
-
position?: number;
|
|
93
|
-
member?: GuildMember;
|
|
94
|
-
textChannel?: GuildTextBasedChannel;
|
|
95
|
-
message?: Message;
|
|
96
|
-
metadata?: any;
|
|
97
|
-
}): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
100
|
-
*
|
|
101
|
-
* @returns {Promise<void>}
|
|
102
|
-
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
103
|
-
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
104
|
-
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
105
|
-
* @param {Object} [options] Optional options
|
|
106
|
-
* @param {boolean} [options.skip=false]
|
|
107
|
-
* Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
|
|
108
|
-
* If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
|
|
109
|
-
* @param {number} [options.position=0] Position of the song/playlist to add to the queue,
|
|
110
|
-
* <= 0 to add to the end of the queue.
|
|
111
|
-
* @param {boolean} [options.unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
|
|
112
|
-
* (after the playing song if exists)
|
|
113
|
-
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
114
|
-
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
115
|
-
* @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)
|
|
116
|
-
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
117
|
-
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
118
|
-
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
119
|
-
* @deprecated Use {@link DisTube#play} instead
|
|
120
|
-
*/
|
|
121
|
-
playVoiceChannel(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist | null, options?: {
|
|
73
|
+
play(voiceChannel: VoiceBasedChannel, song: string | Song | SearchResult | Playlist, options?: {
|
|
122
74
|
skip?: boolean;
|
|
123
75
|
unshift?: boolean;
|
|
124
76
|
position?: number;
|
|
@@ -133,7 +85,7 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
133
85
|
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
134
86
|
* @param {Object} [options] Optional options
|
|
135
87
|
* @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
|
|
136
|
-
* @param {Object} [options.properties
|
|
88
|
+
* @param {Object} [options.properties] Additional properties such as `name`
|
|
137
89
|
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
138
90
|
* @param {*} [options.metadata] Metadata
|
|
139
91
|
* @example
|
|
@@ -151,35 +103,6 @@ export declare class DisTube extends TypedEmitter<DisTubeEvents> {
|
|
|
151
103
|
parallel?: boolean;
|
|
152
104
|
metadata?: any;
|
|
153
105
|
}): Promise<Playlist>;
|
|
154
|
-
/**
|
|
155
|
-
* <info>Shorthand method of {@link DisTube#createCustomPlaylist} and {@link DisTube#play}
|
|
156
|
-
*
|
|
157
|
-
* If you doesn't have a user message (interaction,...),
|
|
158
|
-
* see {@link DisTube#createCustomPlaylist} example</info>
|
|
159
|
-
*
|
|
160
|
-
* Play or add array of video urls.
|
|
161
|
-
* {@link DisTube#event:playSong} or {@link DisTube#event:addList} will be emitted
|
|
162
|
-
* with `playlist`'s properties include `properties` parameter's properties such as
|
|
163
|
-
* `user`, `songs`, `duration`, `formattedDuration`, `thumbnail` like {@link Playlist}
|
|
164
|
-
* @returns {Promise<void>}
|
|
165
|
-
* @param {Discord.Message} message A message from guild channel
|
|
166
|
-
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
167
|
-
* @param {Object} [properties={}] Additional properties for playlist such as `name`
|
|
168
|
-
* @param {Object} [options] Optional options
|
|
169
|
-
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
170
|
-
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
171
|
-
* (after the playing song if exists)
|
|
172
|
-
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
173
|
-
* @deprecated Use {@link DisTube#createCustomPlaylist} and {@link DisTube#play} instead
|
|
174
|
-
*/
|
|
175
|
-
playCustomPlaylist(message: Message<true>, songs: Array<string | Song | SearchResult>, properties?: Record<string, any>, options?: {
|
|
176
|
-
skip?: boolean;
|
|
177
|
-
/** @deprecated */
|
|
178
|
-
unshift?: boolean;
|
|
179
|
-
position?: number;
|
|
180
|
-
parallel?: boolean;
|
|
181
|
-
metadata?: any;
|
|
182
|
-
}): Promise<void>;
|
|
183
106
|
/**
|
|
184
107
|
* Search for a song. You can customize how user answers instead of send a number.
|
|
185
108
|
* Then use {@link DisTube#play} to play it.
|
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,EACZ,IAAI,
|
|
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,EAOL,MAAM,GAAG,CAAC;AACX,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAe,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACtH,OAAO,KAAK,EAAE,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js
CHANGED
|
@@ -9,7 +9,6 @@ const ytsr_1 = __importDefault(require("@distube/ytsr"));
|
|
|
9
9
|
const util_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
|
|
13
12
|
// Cannot be `import` as it's not under TS root dir
|
|
14
13
|
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
|
|
15
14
|
exports.version = require("../package.json").version;
|
|
@@ -67,12 +66,9 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
67
66
|
* DisTube filters
|
|
68
67
|
* @type {Filters}
|
|
69
68
|
*/
|
|
70
|
-
this.filters = _1.defaultFilters;
|
|
71
|
-
Object.assign(this.filters, this.options.customFilters);
|
|
69
|
+
this.filters = { ..._1.defaultFilters, ...this.options.customFilters };
|
|
72
70
|
// Default plugin
|
|
73
71
|
this.options.plugins.push(new _1.HTTPPlugin(), new _1.HTTPSPlugin());
|
|
74
|
-
if (this.options.youtubeDL)
|
|
75
|
-
this.options.plugins.push(new _1.YouTubeDLPlugin(this.options.updateYouTubeDL));
|
|
76
72
|
this.options.plugins.map(p => p.init(this));
|
|
77
73
|
/**
|
|
78
74
|
* Extractor Plugins
|
|
@@ -97,45 +93,52 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
97
93
|
get version() {
|
|
98
94
|
return exports.version;
|
|
99
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
98
|
+
*
|
|
99
|
+
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
100
|
+
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
101
|
+
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
102
|
+
* @param {Object} [options] Optional options
|
|
103
|
+
* @param {boolean} [options.skip=false]
|
|
104
|
+
* Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
|
|
105
|
+
* If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
|
|
106
|
+
* @param {number} [options.position=0] Position of the song/playlist to add to the queue,
|
|
107
|
+
* <= 0 to add to the end of the queue.
|
|
108
|
+
* @param {boolean} [options.unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
|
|
109
|
+
* (after the playing song if exists)
|
|
110
|
+
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
111
|
+
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
112
|
+
* @param {Discord.Message} [options.message] Called message (For built-in search events. If this is a {@link https://developer.mozilla.org/en-US/docs/Glossary/Falsy|falsy value}, it will play the first result instead)
|
|
113
|
+
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
114
|
+
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
115
|
+
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
116
|
+
* @example
|
|
117
|
+
* client.on('message', (message) => {
|
|
118
|
+
* if (!message.content.startsWith(config.prefix)) return;
|
|
119
|
+
* const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
|
|
120
|
+
* const command = args.shift();
|
|
121
|
+
* if (command == "play")
|
|
122
|
+
* distube.play(message.member.voice?.channel, args.join(" "), {
|
|
123
|
+
* member: message.member,
|
|
124
|
+
* textChannel: message.channel,
|
|
125
|
+
* message
|
|
126
|
+
* });
|
|
127
|
+
* });
|
|
128
|
+
* @returns {Promise<void>}
|
|
129
|
+
*/
|
|
100
130
|
async play(voiceChannel, song, options = {}) {
|
|
101
|
-
if ((0, _1.isMessageInstance)(voiceChannel)) {
|
|
102
|
-
process.emitWarning("Passing Message for DisTube#play is deprecated, use BaseGuildVoiceChannel instead.", "DeprecationWarning");
|
|
103
|
-
const message = voiceChannel;
|
|
104
|
-
if (!song)
|
|
105
|
-
throw new _1.DisTubeError("INVALID_TYPE", ["string", "Song", "SearchResult", "Playlist"], song, "song");
|
|
106
|
-
if (!(0, _1.isMessageInstance)(message))
|
|
107
|
-
throw new _1.DisTubeError("INVALID_TYPE", "Discord.Message", message, "message");
|
|
108
|
-
if (typeof options !== "object" || Array.isArray(options)) {
|
|
109
|
-
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
110
|
-
}
|
|
111
|
-
const textChannel = message.channel;
|
|
112
|
-
const { skip, unshift, metadata } = Object.assign({ skip: false, unshift: false }, options);
|
|
113
|
-
const member = message.member;
|
|
114
|
-
const vc = member.voice.channel;
|
|
115
|
-
if (!vc)
|
|
116
|
-
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
117
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
118
|
-
return this.play(vc, song, {
|
|
119
|
-
member,
|
|
120
|
-
textChannel,
|
|
121
|
-
skip,
|
|
122
|
-
message,
|
|
123
|
-
unshift,
|
|
124
|
-
metadata,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
131
|
if (!(0, _1.isSupportedVoiceChannel)(voiceChannel)) {
|
|
128
132
|
throw new _1.DisTubeError("INVALID_TYPE", "BaseGuildVoiceChannel", voiceChannel, "voiceChannel");
|
|
129
133
|
}
|
|
130
|
-
if (
|
|
134
|
+
if (!(0, util_1.isObject)(options))
|
|
131
135
|
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
member: voiceChannel.guild.me,
|
|
136
|
+
const { textChannel, member, skip, message, metadata } = {
|
|
137
|
+
member: voiceChannel.guild.me ?? undefined,
|
|
138
|
+
textChannel: options?.message?.channel,
|
|
136
139
|
skip: false,
|
|
137
|
-
|
|
138
|
-
}
|
|
140
|
+
...options,
|
|
141
|
+
};
|
|
139
142
|
let position = Number(options.position);
|
|
140
143
|
if (!position) {
|
|
141
144
|
if (skip && position !== 0)
|
|
@@ -143,13 +146,15 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
143
146
|
else
|
|
144
147
|
position = 0;
|
|
145
148
|
}
|
|
146
|
-
if (unshift) {
|
|
147
|
-
process.emitWarning("'unshift' option in DisTube#play is deprecated, use 'position' instead.", "DeprecationWarning");
|
|
148
|
-
position = 1;
|
|
149
|
-
}
|
|
150
149
|
if (message && !(0, _1.isMessageInstance)(message)) {
|
|
151
150
|
throw new _1.DisTubeError("INVALID_TYPE", ["Discord.Message", "a falsy value"], message, "options.message");
|
|
152
151
|
}
|
|
152
|
+
if (textChannel && !(0, _1.isTextChannelInstance)(textChannel)) {
|
|
153
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Discord.GuildTextBasedChannel", textChannel, "options.textChannel");
|
|
154
|
+
}
|
|
155
|
+
if (member && !(0, _1.isMemberInstance)(member)) {
|
|
156
|
+
throw new _1.DisTubeError("INVALID_TYPE", "Discord.GuildMember", member, "options.member");
|
|
157
|
+
}
|
|
153
158
|
try {
|
|
154
159
|
if (typeof song === "string") {
|
|
155
160
|
for (const plugin of this.customPlugins) {
|
|
@@ -169,14 +174,17 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
169
174
|
song = await this.handler.resolvePlaylist(song, { member, metadata });
|
|
170
175
|
}
|
|
171
176
|
if (typeof song === "string" && !(0, util_1.isURL)(song)) {
|
|
172
|
-
if (!message)
|
|
177
|
+
if (!message) {
|
|
173
178
|
song = (await this.search(song, { limit: 1 }))[0];
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const result = await this.handler.searchSong(message, song);
|
|
182
|
+
if (!result)
|
|
183
|
+
return;
|
|
184
|
+
song = result;
|
|
185
|
+
}
|
|
176
186
|
}
|
|
177
187
|
song = await this.handler.resolveSong(song, { member, metadata });
|
|
178
|
-
if (!song)
|
|
179
|
-
return;
|
|
180
188
|
if (song instanceof _1.Playlist) {
|
|
181
189
|
await this.handler.handlePlaylist(voiceChannel, song, { textChannel, skip, position });
|
|
182
190
|
}
|
|
@@ -218,40 +226,13 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
218
226
|
this.emitError(e, textChannel);
|
|
219
227
|
}
|
|
220
228
|
}
|
|
221
|
-
/**
|
|
222
|
-
* Play / add a song or playlist from url. Search and play a song if it is not a valid url.
|
|
223
|
-
*
|
|
224
|
-
* @returns {Promise<void>}
|
|
225
|
-
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
226
|
-
* @param {string|Song|SearchResult|Playlist} song URL | Search string |
|
|
227
|
-
* {@link Song} | {@link SearchResult} | {@link Playlist}
|
|
228
|
-
* @param {Object} [options] Optional options
|
|
229
|
-
* @param {boolean} [options.skip=false]
|
|
230
|
-
* Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
|
|
231
|
-
* If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
|
|
232
|
-
* @param {number} [options.position=0] Position of the song/playlist to add to the queue,
|
|
233
|
-
* <= 0 to add to the end of the queue.
|
|
234
|
-
* @param {boolean} [options.unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
|
|
235
|
-
* (after the playing song if exists)
|
|
236
|
-
* @param {Discord.GuildMember} [options.member] Requested user (default is your bot)
|
|
237
|
-
* @param {Discord.BaseGuildTextChannel} [options.textChannel] Default {@link Queue#textChannel}
|
|
238
|
-
* @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)
|
|
239
|
-
* @param {*} [options.metadata] Optional metadata that can be attached to the song/playlist will be played,
|
|
240
|
-
* This is useful for identification purposes when the song/playlist is passed around in events.
|
|
241
|
-
* See {@link Song#metadata} or {@link Playlist#metadata}
|
|
242
|
-
* @deprecated Use {@link DisTube#play} instead
|
|
243
|
-
*/
|
|
244
|
-
async playVoiceChannel(voiceChannel, song, options = {}) {
|
|
245
|
-
process.emitWarning("DisTube#playVoiceChannel is deprecated, use DisTube#play instead.", "DeprecationWarning");
|
|
246
|
-
return this.play(voiceChannel, song, options);
|
|
247
|
-
}
|
|
248
229
|
/**
|
|
249
230
|
* Create a custom playlist
|
|
250
231
|
* @returns {Promise<Playlist>}
|
|
251
232
|
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
252
233
|
* @param {Object} [options] Optional options
|
|
253
234
|
* @param {Discord.GuildMember} [options.message] A message from guild channel | A guild member
|
|
254
|
-
* @param {Object} [options.properties
|
|
235
|
+
* @param {Object} [options.properties] Additional properties such as `name`
|
|
255
236
|
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
256
237
|
* @param {*} [options.metadata] Metadata
|
|
257
238
|
* @example
|
|
@@ -264,7 +245,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
264
245
|
* distube.play(voiceChannel, playlist, { ... });
|
|
265
246
|
*/
|
|
266
247
|
async createCustomPlaylist(songs, options = {}) {
|
|
267
|
-
const { member, properties, parallel, metadata } =
|
|
248
|
+
const { member, properties, parallel, metadata } = { parallel: true, ...options };
|
|
268
249
|
if (!Array.isArray(songs))
|
|
269
250
|
throw new _1.DisTubeError("INVALID_TYPE", "Array", songs, "songs");
|
|
270
251
|
if (!songs.length)
|
|
@@ -291,73 +272,6 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
291
272
|
}
|
|
292
273
|
return new _1.Playlist(resolvedSongs, { member, properties, metadata });
|
|
293
274
|
}
|
|
294
|
-
/**
|
|
295
|
-
* <info>Shorthand method of {@link DisTube#createCustomPlaylist} and {@link DisTube#play}
|
|
296
|
-
*
|
|
297
|
-
* If you doesn't have a user message (interaction,...),
|
|
298
|
-
* see {@link DisTube#createCustomPlaylist} example</info>
|
|
299
|
-
*
|
|
300
|
-
* Play or add array of video urls.
|
|
301
|
-
* {@link DisTube#event:playSong} or {@link DisTube#event:addList} will be emitted
|
|
302
|
-
* with `playlist`'s properties include `properties` parameter's properties such as
|
|
303
|
-
* `user`, `songs`, `duration`, `formattedDuration`, `thumbnail` like {@link Playlist}
|
|
304
|
-
* @returns {Promise<void>}
|
|
305
|
-
* @param {Discord.Message} message A message from guild channel
|
|
306
|
-
* @param {Array<string|Song|SearchResult>} songs Array of url, Song or SearchResult
|
|
307
|
-
* @param {Object} [properties={}] Additional properties for playlist such as `name`
|
|
308
|
-
* @param {Object} [options] Optional options
|
|
309
|
-
* @param {boolean} [options.skip=false] Skip the playing song (if exists) and play the added song/playlist instantly
|
|
310
|
-
* @param {boolean} [options.unshift=false] Add the song/playlist to the beginning of the queue
|
|
311
|
-
* (after the playing song if exists)
|
|
312
|
-
* @param {boolean} [options.parallel=true] Whether or not fetch the songs in parallel
|
|
313
|
-
* @deprecated Use {@link DisTube#createCustomPlaylist} and {@link DisTube#play} instead
|
|
314
|
-
*/
|
|
315
|
-
async playCustomPlaylist(message, songs, properties = {}, options = {}) {
|
|
316
|
-
process.emitWarning("DisTube#playCustomPlaylist is deprecated, use DisTube#createCustomPlaylist and DisTube#play instead.", "DeprecationWarning");
|
|
317
|
-
try {
|
|
318
|
-
if (typeof options !== "object" || Array.isArray(options)) {
|
|
319
|
-
throw new _1.DisTubeError("INVALID_TYPE", "object", options, "options");
|
|
320
|
-
}
|
|
321
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
322
|
-
const { skip, unshift, parallel, metadata } = Object.assign({
|
|
323
|
-
skip: false,
|
|
324
|
-
unshift: false,
|
|
325
|
-
parallel: true,
|
|
326
|
-
}, options);
|
|
327
|
-
let position = Number(options.position);
|
|
328
|
-
if (!position) {
|
|
329
|
-
if (skip && position !== 0)
|
|
330
|
-
position = 1;
|
|
331
|
-
else
|
|
332
|
-
position = 0;
|
|
333
|
-
}
|
|
334
|
-
if (unshift)
|
|
335
|
-
position = 1;
|
|
336
|
-
const queue = this.getQueue(message);
|
|
337
|
-
const queuing = queue && !queue.taskQueue.hasResolveTask;
|
|
338
|
-
if (queuing)
|
|
339
|
-
await queue?.taskQueue.queuing(true);
|
|
340
|
-
try {
|
|
341
|
-
const playlist = await this.createCustomPlaylist(songs, {
|
|
342
|
-
member: message.member ?? undefined,
|
|
343
|
-
properties,
|
|
344
|
-
parallel,
|
|
345
|
-
metadata,
|
|
346
|
-
});
|
|
347
|
-
const voice = message.member?.voice?.channel;
|
|
348
|
-
if (!voice)
|
|
349
|
-
throw new _1.DisTubeError("NOT_IN_VOICE");
|
|
350
|
-
await this.play(voice, playlist, { textChannel: message.channel, skip, position, metadata });
|
|
351
|
-
}
|
|
352
|
-
finally {
|
|
353
|
-
if (queuing)
|
|
354
|
-
queue?.taskQueue.resolve();
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
catch (e) {
|
|
358
|
-
this.emitError(e, message.channel);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
275
|
/**
|
|
362
276
|
* Search for a song. You can customize how user answers instead of send a number.
|
|
363
277
|
* Then use {@link DisTube#play} to play it.
|
|
@@ -371,7 +285,7 @@ class DisTube extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
371
285
|
* @returns {Promise<Array<SearchResult>>} Array of results
|
|
372
286
|
*/
|
|
373
287
|
async search(string, options = {}) {
|
|
374
|
-
const opts =
|
|
288
|
+
const opts = { type: "video", limit: 10, safeSearch: false, ...options };
|
|
375
289
|
if (typeof opts.type !== "string" || !["video", "playlist"].includes(opts.type)) {
|
|
376
290
|
throw new _1.DisTubeError("INVALID_TYPE", ["video", "playlist"], opts.type, "options.type");
|
|
377
291
|
}
|