discord-player 6.0.0-dev.2 → 6.0.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -24
- package/dist/index.d.ts +586 -729
- package/dist/index.js +1532 -2002
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1541 -2013
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# Discord Player
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Discord Player is a powerful framework for JavaScript and TypeScript, built on top of **[@discord.js/voice](https://npm.im/@discordjs/voice)** library.
|
|
4
|
+
It provides easy set of customizable tools to develop Discord Music bots.
|
|
4
5
|
|
|
5
6
|
[](https://npmjs.com/discord-player)
|
|
6
7
|
[](https://npmjs.com/discord-player)
|
|
7
8
|
[](https://androz2091.fr/discord)
|
|
8
|
-
[](https://wakatime.com/badge/github/Androz2091/discord-player)
|
|
9
|
-
[](https://www.codefactor.io/repository/github/androz2091/discord-player/overview/v5)
|
|
10
9
|
|
|
11
10
|
## Installation
|
|
12
11
|
|
|
@@ -19,19 +18,19 @@ $ npm install --save discord-player
|
|
|
19
18
|
### Install **[@discordjs/opus](https://npmjs.com/package/@discordjs/opus)**
|
|
20
19
|
|
|
21
20
|
```sh
|
|
22
|
-
$ npm install --save @discordjs/opus # Native
|
|
21
|
+
$ npm install --save @discordjs/opus # Native (best performance)
|
|
23
22
|
|
|
24
23
|
# or
|
|
25
|
-
$ npm install --save opusscript # WASM
|
|
24
|
+
$ npm install --save opusscript # WASM (near native performance)
|
|
26
25
|
```
|
|
27
26
|
|
|
28
27
|
### Install streaming library (if you want to play from youtube)
|
|
29
28
|
|
|
30
29
|
```sh
|
|
31
|
-
$ npm install --save
|
|
30
|
+
$ npm install --save ytdl-core
|
|
32
31
|
|
|
33
32
|
# or
|
|
34
|
-
$ npm install --save
|
|
33
|
+
$ npm install --save play-dl
|
|
35
34
|
```
|
|
36
35
|
|
|
37
36
|
### Install FFmpeg or Avconv
|
|
@@ -44,9 +43,10 @@ $ npm install --save ytdl-core
|
|
|
44
43
|
|
|
45
44
|
- Simple & easy to use 🤘
|
|
46
45
|
- Beginner friendly 😱
|
|
47
|
-
-
|
|
46
|
+
- **A LOT OF AUDIO FILTERS** (discord-player has total of around 64 built-in filter presets which can be *extended even more!*) 🎸
|
|
48
47
|
- Lavalink compatible 15 band equalizer 🎚️
|
|
49
48
|
- Digital biquad filters support
|
|
49
|
+
- Digital Signal Processing utilities
|
|
50
50
|
- Lightweight ☁️
|
|
51
51
|
- Custom extractors support 🌌
|
|
52
52
|
- Multiple sources support ✌
|
|
@@ -146,25 +146,71 @@ client.on('interactionCreate', async (interaction) => {
|
|
|
146
146
|
client.login('BOT_TOKEN');
|
|
147
147
|
```
|
|
148
148
|
|
|
149
|
+
### Accessing player instance
|
|
150
|
+
|
|
151
|
+
Polluting client like this could be a bad idea:
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
client.player = player;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
discord-player provides singleton support to avoid this type of pollution:
|
|
158
|
+
|
|
159
|
+
```diff
|
|
160
|
+
- const player = new Player(client);
|
|
161
|
+
+ const player = Player.singleton(client);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
`Player.singleton()` creates a single instance of player which is shared in the future. You can simply do `Player.singleton()` to access player instance whenever
|
|
165
|
+
you want without polluting client.
|
|
166
|
+
|
|
149
167
|
## Supported sources
|
|
150
168
|
|
|
151
|
-
By default, discord-player supports the following sources:
|
|
169
|
+
By default, discord-player **does not support anything** (including search operation and streaming). Luckily, discord-player supports the following sources with the help of [@discord-player/extractor](https://npm.im/@discord-player/extractor) which comes pre-installed with discord-player:
|
|
170
|
+
|
|
171
|
+
- Local file (You must set the search engine to `QueryType.FILE` in order to play local files, backed by `attachment extractor`)
|
|
172
|
+
- Raw attachments (backed by `attachment extractor`)
|
|
173
|
+
- Spotify (backed by `ysa extractor`)
|
|
174
|
+
- Apple Music (backed by `ysa extractor`)
|
|
175
|
+
- YouTube (backed by `ysa extractor`)
|
|
176
|
+
- Vimeo (backed by `vimeo extractor`)
|
|
177
|
+
- Reverbnation (backed by `reverbnation extractor`)
|
|
178
|
+
- SoundCloud (backed by `soundcloud extractor`)
|
|
179
|
+
|
|
180
|
+
If you dont want to stream from certain extractors, you can block them by passing `blockStreamFrom: [id, id, ...]` to player instantiation options.
|
|
181
|
+
Disabling youtube streaming completely would be as easy as:
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
import { Player } from 'discord-player';
|
|
185
|
+
import { YouTubeExtractor } from '@discord-player/extractor';
|
|
186
|
+
|
|
187
|
+
const player = new Player(client, {
|
|
188
|
+
blockStreamFrom: [
|
|
189
|
+
// now your bot will no longer be able to use
|
|
190
|
+
// youtube extractor to play audio even if the track was
|
|
191
|
+
// extracted from youtube
|
|
192
|
+
YouTubeExtractor.identifier
|
|
193
|
+
],
|
|
194
|
+
blockExtractors: [
|
|
195
|
+
// this will block the listed extractors from being
|
|
196
|
+
// able to query metadata (aka search results parsing)
|
|
197
|
+
// This example disables youtube search, spotify bridge
|
|
198
|
+
// and apple music bridge
|
|
199
|
+
YouTubeExtractor.identifier
|
|
200
|
+
]
|
|
201
|
+
});
|
|
202
|
+
```
|
|
152
203
|
|
|
153
|
-
|
|
154
|
-
- Raw attachments
|
|
155
|
-
- Spotify (Streamed from youtube)
|
|
156
|
-
- Apple Music (Streamed from youtube)
|
|
157
|
-
- Vimeo
|
|
158
|
-
- Reverbnation
|
|
159
|
-
- SoundCloud
|
|
204
|
+
Likewise, You can also force a specific extractor to resolve your search query. This is useful in some cases where you don't want to use other sources.
|
|
160
205
|
|
|
161
|
-
You can also force a specific extractor to resolve your search query. This is useful in some cases where you don't want to use other sources.
|
|
162
206
|
You can do so by using `ext:<EXTRACTOR_IDENTIFIER>` in `searchEngine` value. Example:
|
|
163
207
|
|
|
164
208
|
```js
|
|
209
|
+
import { SoundCloudExtractor } from '@discord-player/extractor';
|
|
210
|
+
|
|
165
211
|
const result = await player.search(query, {
|
|
166
212
|
// always use soundcloud extractor
|
|
167
|
-
searchEngine:
|
|
213
|
+
searchEngine: SoundCloudExtractor.identifier
|
|
168
214
|
});
|
|
169
215
|
```
|
|
170
216
|
|
|
@@ -181,7 +227,7 @@ Discord Player supports various audio filters. There are 4 types of audio filter
|
|
|
181
227
|
The most common and powerful method is FFmpeg. It supports a lot of audio filters. To set ffmpeg filter, you can do:
|
|
182
228
|
|
|
183
229
|
```js
|
|
184
|
-
await queue.filters.ffmpeg.
|
|
230
|
+
await queue.filters.ffmpeg.toggle(['bassboost', 'nightcore']);
|
|
185
231
|
```
|
|
186
232
|
|
|
187
233
|
Note that there can be a delay between filters transition in this method.
|
|
@@ -228,6 +274,7 @@ There is no delay between filters transition using this filter.
|
|
|
228
274
|
These bots are made by the community, they can help you build your own!
|
|
229
275
|
|
|
230
276
|
- **[Discord Music Bot](https://github.com/Androz2091/discord-music-bot)** by [Androz2091](https://github.com/Androz2091)
|
|
277
|
+
- [Karasu-Music-Bot](https://github.com/ItsAuric/karasu-music-bot) by [ItsAuric](https://github.com/itsauric)
|
|
231
278
|
- [Dodong](https://github.com/nizeic/Dodong) by [nizeic](https://github.com/nizeic)
|
|
232
279
|
- [Musico](https://github.com/Whirl21/Musico) by [Whirl21](https://github.com/Whirl21)
|
|
233
280
|
- [Melody](https://github.com/NerdyTechy/Melody) by [NerdyTechy](https://github.com/NerdyTechy)
|
|
@@ -236,7 +283,9 @@ These bots are made by the community, they can help you build your own!
|
|
|
236
283
|
- [AtlantaBot](https://github.com/Androz2091/AtlantaBot) by [Androz2091](https://github.com/Androz2091) (**outdated**)
|
|
237
284
|
- [Discord-Music](https://github.com/inhydrox/discord-music) by [inhydrox](https://github.com/inhydrox) (**outdated**)
|
|
238
285
|
|
|
239
|
-
### Use cookies
|
|
286
|
+
### Use youtube cookies
|
|
287
|
+
|
|
288
|
+
Using youtube cookies helps you to prevent frequent ratelimits.
|
|
240
289
|
|
|
241
290
|
```js
|
|
242
291
|
const player = new Player(client, {
|
|
@@ -250,7 +299,7 @@ const player = new Player(client, {
|
|
|
250
299
|
});
|
|
251
300
|
```
|
|
252
301
|
|
|
253
|
-
> Note:
|
|
302
|
+
> Note: The above option is also passed to `ytdl-core` but not `play-dl`. Follow [this instruction](https://github.com/play-dl/play-dl/blob/1ae7ba8fcea8b93293af5de9e19eca3c2a491804/instructions/README.md) for play-dl config.
|
|
254
303
|
|
|
255
304
|
### Use custom proxies
|
|
256
305
|
|
|
@@ -271,7 +320,9 @@ const player = new Player(client, {
|
|
|
271
320
|
> You may also create a simple proxy server and forward requests through it.
|
|
272
321
|
> See **[https://github.com/http-party/node-http-proxy](https://github.com/http-party/node-http-proxy)** for more info.
|
|
273
322
|
|
|
274
|
-
|
|
323
|
+
## Stream Hooks
|
|
324
|
+
|
|
325
|
+
### onBeforeCreateStream
|
|
275
326
|
|
|
276
327
|
Discord Player by default uses registered extractors to stream audio. If you need to override what needs to be streamed, you can use this hook.
|
|
277
328
|
|
|
@@ -289,5 +340,23 @@ const queue = player.nodes.create(..., {
|
|
|
289
340
|
});
|
|
290
341
|
```
|
|
291
342
|
|
|
292
|
-
|
|
293
|
-
streams. `source` here will be a track source. Streams from `onBeforeCreateStream` are then piped to `FFmpeg` and
|
|
343
|
+
`<GuildQueue>.onBeforeCreateStream` is called before actually downloading the stream. It is a different concept from extractors, where you are **just** downloading
|
|
344
|
+
streams. `source` here will be a track source. Streams from `onBeforeCreateStream` are then piped to `FFmpeg` and sent to `onAfterCreateStream` hook.
|
|
345
|
+
|
|
346
|
+
### onAfterCreateStream
|
|
347
|
+
|
|
348
|
+
This hook can be used to post-process pcm stream. This is the final step before creating audio resource. Example:
|
|
349
|
+
|
|
350
|
+
```js
|
|
351
|
+
const queue = player.nodes.create(..., {
|
|
352
|
+
...,
|
|
353
|
+
async onAfterCreateStream(pcmStream, queue) {
|
|
354
|
+
// return opus encoded stream
|
|
355
|
+
const encoder = new OpusEncoder();
|
|
356
|
+
return {
|
|
357
|
+
stream: encoder.encode(pcmStream),
|
|
358
|
+
type: StreamType.Opus
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
```
|