discord-player 6.0.0-dev.0 → 6.0.0-dev.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/LICENSE +1 -1
- package/README.md +170 -119
- package/dist/index.d.ts +837 -207
- package/dist/index.js +2950 -32
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2911 -18
- package/dist/index.mjs.map +1 -0
- package/package.json +25 -36
- package/dist/Player.js +0 -563
- package/dist/Structures/ExtractorModel.js +0 -65
- package/dist/Structures/PlayerError.js +0 -48
- package/dist/Structures/Playlist.js +0 -108
- package/dist/Structures/Queue.js +0 -788
- package/dist/Structures/Track.js +0 -155
- package/dist/VoiceInterface/StreamDispatcher.js +0 -227
- package/dist/VoiceInterface/VoiceUtils.js +0 -75
- package/dist/VoiceInterface/VolumeTransformer.js +0 -120
- package/dist/smoothVolume.js +0 -13
- package/dist/types/types.js +0 -58
- package/dist/utils/AudioFilters.js +0 -109
- package/dist/utils/QueryResolver.js +0 -68
- package/dist/utils/Util.js +0 -123
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Discord Player
|
|
2
|
+
|
|
2
3
|
Complete framework to facilitate music commands using **[discord.js](https://discord.js.org)**.
|
|
3
4
|
|
|
4
5
|
[](https://npmjs.com/discord-player)
|
|
@@ -7,8 +8,6 @@ Complete framework to facilitate music commands using **[discord.js](https://dis
|
|
|
7
8
|
[](https://wakatime.com/badge/github/Androz2091/discord-player)
|
|
8
9
|
[](https://www.codefactor.io/repository/github/androz2091/discord-player/overview/v5)
|
|
9
10
|
|
|
10
|
-
> ⚠️ Discord Player v6 (Discord.js v14) WIP
|
|
11
|
-
|
|
12
11
|
## Installation
|
|
13
12
|
|
|
14
13
|
### Install **[discord-player](https://npmjs.com/package/discord-player)**
|
|
@@ -20,26 +19,40 @@ $ npm install --save discord-player
|
|
|
20
19
|
### Install **[@discordjs/opus](https://npmjs.com/package/@discordjs/opus)**
|
|
21
20
|
|
|
22
21
|
```sh
|
|
23
|
-
$ npm install --save @discordjs/opus
|
|
22
|
+
$ npm install --save @discordjs/opus # Native bindings via napi
|
|
23
|
+
|
|
24
|
+
# or
|
|
25
|
+
$ npm install --save opusscript # WASM bindings
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
### Install
|
|
27
|
-
|
|
28
|
+
### Install streaming library (if you want to play from youtube)
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
$ npm install --save play-dl # discord-player prefers play-dl over ytdl-core if both of them are installed
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
# or
|
|
34
|
+
$ npm install --save ytdl-core
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Install FFmpeg or Avconv
|
|
30
38
|
|
|
31
|
-
-
|
|
39
|
+
- Official FFMPEG Website: **[https://www.ffmpeg.org/download.html](https://www.ffmpeg.org/download.html)**
|
|
40
|
+
- Node Module (FFMPEG): **[https://npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
|
|
41
|
+
- Avconv: **[https://libav.org/download](https://libav.org/download)**
|
|
32
42
|
|
|
33
43
|
# Features
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
-
|
|
44
|
+
|
|
45
|
+
- Simple & easy to use 🤘
|
|
46
|
+
- Beginner friendly 😱
|
|
47
|
+
- Audio filters 🎸
|
|
48
|
+
- Lavalink compatible 15 band equalizer 🎚️
|
|
49
|
+
- Digital biquad filters support
|
|
50
|
+
- Lightweight ☁️
|
|
51
|
+
- Custom extractors support 🌌
|
|
52
|
+
- Multiple sources support ✌
|
|
53
|
+
- Play in multiple servers at the same time 🚗
|
|
54
|
+
- Does not inject anything to discord.js or your discord.js client 💉
|
|
55
|
+
- Allows you to have full control over what is going to be streamed 👑
|
|
43
56
|
|
|
44
57
|
## [Documentation](https://discord-player.js.org)
|
|
45
58
|
|
|
@@ -48,161 +61,204 @@ $ npm install --save @discordjs/opus
|
|
|
48
61
|
First of all, you will need to register slash commands:
|
|
49
62
|
|
|
50
63
|
```js
|
|
51
|
-
const { REST } = require(
|
|
52
|
-
const { Routes } = require(
|
|
53
|
-
|
|
54
|
-
const commands = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const { REST } = require('@discordjs/rest');
|
|
65
|
+
const { Routes, ApplicationCommandOptionType } = require('discord.js');
|
|
66
|
+
|
|
67
|
+
const commands = [
|
|
68
|
+
{
|
|
69
|
+
name: 'play',
|
|
70
|
+
description: 'Plays a song!',
|
|
71
|
+
options: [
|
|
72
|
+
{
|
|
73
|
+
name: 'query',
|
|
74
|
+
type: ApplicationCommandOptionType.String,
|
|
75
|
+
description: 'The song you want to play',
|
|
76
|
+
required: true
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
];
|
|
66
81
|
|
|
67
|
-
const rest = new REST({ version:
|
|
82
|
+
const rest = new REST({ version: '10' }).setToken('BOT_TOKEN');
|
|
68
83
|
|
|
69
84
|
(async () => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
} catch (error) {
|
|
80
|
-
console.error(error);
|
|
81
|
-
}
|
|
85
|
+
try {
|
|
86
|
+
console.log('Started refreshing application [/] commands.');
|
|
87
|
+
|
|
88
|
+
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
|
|
89
|
+
|
|
90
|
+
console.log('Successfully reloaded application [/] commands.');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error(error);
|
|
93
|
+
}
|
|
82
94
|
})();
|
|
83
95
|
```
|
|
84
96
|
|
|
85
97
|
Now you can implement your bot's logic:
|
|
86
98
|
|
|
87
99
|
```js
|
|
88
|
-
const { Client
|
|
89
|
-
const client = new Discord.Client({
|
|
90
|
-
|
|
100
|
+
const { Client } = require('discord.js');
|
|
101
|
+
const client = new Discord.Client({
|
|
102
|
+
intents: ['Guilds', 'GuildVoiceStates']
|
|
103
|
+
});
|
|
104
|
+
const { Player } = require('discord-player');
|
|
91
105
|
|
|
92
106
|
// Create a new Player (you don't need any API Key)
|
|
93
107
|
const player = new Player(client);
|
|
94
108
|
|
|
95
|
-
// add the
|
|
96
|
-
player.on(
|
|
109
|
+
// add the start and finish event so when a song will be played this message will be sent
|
|
110
|
+
player.events.on('playerStart', (queue, track) => queue.metadata.channel.send(`🎶 | Now playing **${track.title}**!`));
|
|
111
|
+
player.events.on('playerFinish', (queue, track) => queue.metadata.channel.send(`🎶 | Now playing **${track.title}**!`));
|
|
97
112
|
|
|
98
|
-
client.once(
|
|
113
|
+
client.once('ready', () => {
|
|
99
114
|
console.log("I'm ready !");
|
|
100
115
|
});
|
|
101
116
|
|
|
102
|
-
client.on(
|
|
103
|
-
if (!interaction.
|
|
117
|
+
client.on('interactionCreate', async (interaction) => {
|
|
118
|
+
if (!interaction.isChatInputCommand()) return;
|
|
104
119
|
|
|
105
120
|
// /play track:Despacito
|
|
106
121
|
// will play "Despacito" in the voice channel
|
|
107
|
-
if (interaction.commandName ===
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// verify vc connection
|
|
122
|
+
if (interaction.commandName === 'play') {
|
|
123
|
+
const voiceChannel = interaction.member.voice.channelId;
|
|
124
|
+
if (!voiceChannel) return await interaction.reply({ content: 'You are not in a voice channel!', ephemeral: true });
|
|
125
|
+
if (interaction.guild.members.me.voice.channelId && voiceChannel !== interaction.guild.members.me.voice.channelId)
|
|
126
|
+
return await interaction.reply({ content: 'You are not in my voice channel!', ephemeral: true });
|
|
127
|
+
await interaction.deferReply({ ephemeral: true });
|
|
128
|
+
const query = interaction.options.getString('query');
|
|
129
|
+
|
|
118
130
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
131
|
+
const res = await player.play(voiceChannel, query, {
|
|
132
|
+
nodeOptions: {
|
|
133
|
+
metadata: {
|
|
134
|
+
channel: interaction.channel
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return await interaction.followUp({ content: `⏱️ | Loading track **${res.track.title}**!` });
|
|
140
|
+
} catch(e) {
|
|
141
|
+
return await interaction.followUp({ content: `Could not play: ${e.message}`, ephemeral: true });
|
|
123
142
|
}
|
|
124
|
-
|
|
125
|
-
await interaction.deferReply();
|
|
126
|
-
const track = await player.search(query, {
|
|
127
|
-
requestedBy: interaction.user
|
|
128
|
-
}).then(x => x.tracks[0]);
|
|
129
|
-
if (!track) return await interaction.followUp({ content: `❌ | Track **${query}** not found!` });
|
|
130
|
-
|
|
131
|
-
queue.play(track);
|
|
132
|
-
|
|
133
|
-
return await interaction.followUp({ content: `⏱️ | Loading track **${track.title}**!` });
|
|
134
143
|
}
|
|
135
144
|
});
|
|
136
145
|
|
|
137
|
-
client.login(
|
|
146
|
+
client.login('BOT_TOKEN');
|
|
138
147
|
```
|
|
139
148
|
|
|
140
|
-
## Supported
|
|
149
|
+
## Supported sources
|
|
150
|
+
|
|
151
|
+
By default, discord-player supports the following sources:
|
|
141
152
|
|
|
142
|
-
|
|
153
|
+
- Local file (You must set the search engine to `QueryType.FILE` in order to play local files)
|
|
154
|
+
- Raw attachments
|
|
155
|
+
- Spotify (Streamed from youtube)
|
|
156
|
+
- Apple Music (Streamed from youtube)
|
|
157
|
+
- Vimeo
|
|
158
|
+
- Reverbnation
|
|
159
|
+
- SoundCloud
|
|
143
160
|
|
|
144
|
-
|
|
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
|
+
You can do so by using `ext:<EXTRACTOR_IDENTIFIER>` in `searchEngine` value. Example:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
const result = await player.search(query, {
|
|
166
|
+
// always use soundcloud extractor
|
|
167
|
+
searchEngine: 'ext:com.discord-player.soundcloudextractor'
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Adding more sources
|
|
145
172
|
|
|
146
173
|
Discord Player provides an **Extractor API** that enables you to use your custom stream extractor with it. Some packages have been made by the community to add new features using this API.
|
|
147
174
|
|
|
148
|
-
|
|
175
|
+
## Audio Filters
|
|
176
|
+
|
|
177
|
+
Discord Player supports various audio filters. There are 4 types of audio filters in discord-player.
|
|
149
178
|
|
|
150
|
-
|
|
151
|
-
You just need to install it using `npm i --save @discord-player/extractor` (discord-player will automatically detect and use it).
|
|
179
|
+
##### FFmpeg
|
|
152
180
|
|
|
153
|
-
|
|
181
|
+
The most common and powerful method is FFmpeg. It supports a lot of audio filters. To set ffmpeg filter, you can do:
|
|
154
182
|
|
|
155
|
-
|
|
183
|
+
```js
|
|
184
|
+
await queue.filters.ffmpeg.setFilters(['bassboost', 'nightcore']);
|
|
185
|
+
```
|
|
156
186
|
|
|
157
|
-
|
|
187
|
+
Note that there can be a delay between filters transition in this method.
|
|
158
188
|
|
|
159
|
-
|
|
189
|
+
##### Equalizer
|
|
160
190
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
191
|
+
This equalizer is very similar to Lavalink's 15 Band Equalizer. To use this, you can do:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
queue.filters.equalizer.setEQ([
|
|
195
|
+
{ band: 0, gain: 0.25 },
|
|
196
|
+
{ band: 1, gain: 0.25 },
|
|
197
|
+
{ band: 2, gain: 0.25 }
|
|
198
|
+
]);
|
|
199
|
+
```
|
|
168
200
|
|
|
169
|
-
|
|
201
|
+
There is no delay between filter transition when using equalizer.
|
|
170
202
|
|
|
171
|
-
|
|
203
|
+
##### Biquad
|
|
172
204
|
|
|
173
|
-
|
|
205
|
+
This filter provides digital biquad filterer to the player. To use this, you can do:
|
|
174
206
|
|
|
175
207
|
```js
|
|
176
|
-
|
|
177
|
-
require("discord-player/smoothVolume");
|
|
208
|
+
import { BiquadFilterType } from 'discord-player';
|
|
178
209
|
|
|
179
|
-
|
|
180
|
-
|
|
210
|
+
queue.filters.biquad.setFilter(BiquadFilterType.LowPass);
|
|
211
|
+
// similarly, you can use other filters such as HighPass, BandPass, Notch, PeakEQ, LowShelf, HighShelf, etc.
|
|
181
212
|
```
|
|
182
213
|
|
|
183
|
-
|
|
214
|
+
There is no delay between filter transition when using biquad filters.
|
|
184
215
|
|
|
185
|
-
|
|
216
|
+
#### Mini Audio Filters
|
|
217
|
+
|
|
218
|
+
This is another type of audio filters provider. It currently supports `Tremolo` and `8D` filters only. To use this, you can do:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
queue.filters.filters.setFilters(['8D']);
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
There is no delay between filters transition using this filter.
|
|
225
|
+
|
|
226
|
+
## Example bots made with Discord Player
|
|
227
|
+
|
|
228
|
+
These bots are made by the community, they can help you build your own!
|
|
229
|
+
|
|
230
|
+
- **[Discord Music Bot](https://github.com/Androz2091/discord-music-bot)** by [Androz2091](https://github.com/Androz2091)
|
|
231
|
+
- [Dodong](https://github.com/nizeic/Dodong) by [nizeic](https://github.com/nizeic)
|
|
232
|
+
- [Musico](https://github.com/Whirl21/Musico) by [Whirl21](https://github.com/Whirl21)
|
|
233
|
+
- [Melody](https://github.com/NerdyTechy/Melody) by [NerdyTechy](https://github.com/NerdyTechy)
|
|
234
|
+
- [Eyesense-Music-Bot](https://github.com/naseif/Eyesense-Music-Bot) by [naseif](https://github.com/naseif)
|
|
235
|
+
- [Music-bot](https://github.com/ZerioDev/Music-bot) by [ZerioDev](https://github.com/ZerioDev)
|
|
236
|
+
- [AtlantaBot](https://github.com/Androz2091/AtlantaBot) by [Androz2091](https://github.com/Androz2091) (**outdated**)
|
|
237
|
+
- [Discord-Music](https://github.com/inhydrox/discord-music) by [inhydrox](https://github.com/inhydrox) (**outdated**)
|
|
238
|
+
|
|
239
|
+
### Use cookies with ytdl-core
|
|
186
240
|
|
|
187
241
|
```js
|
|
188
242
|
const player = new Player(client, {
|
|
189
243
|
ytdlOptions: {
|
|
190
244
|
requestOptions: {
|
|
191
245
|
headers: {
|
|
192
|
-
cookie:
|
|
246
|
+
cookie: 'YOUR_YOUTUBE_COOKIE'
|
|
193
247
|
}
|
|
194
248
|
}
|
|
195
249
|
}
|
|
196
250
|
});
|
|
197
251
|
```
|
|
198
252
|
|
|
253
|
+
> Note: the above option is only used when ytdl-core is being used.
|
|
254
|
+
|
|
199
255
|
### Use custom proxies
|
|
200
256
|
|
|
201
257
|
```js
|
|
202
|
-
const HttpsProxyAgent = require(
|
|
258
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
|
203
259
|
|
|
204
260
|
// Remove "user:pass@" if you don't need to authenticate to your proxy.
|
|
205
|
-
const proxy =
|
|
261
|
+
const proxy = 'http://user:pass@111.111.111.111:8080';
|
|
206
262
|
const agent = HttpsProxyAgent(proxy);
|
|
207
263
|
|
|
208
264
|
const player = new Player(client, {
|
|
@@ -217,26 +273,21 @@ const player = new Player(client, {
|
|
|
217
273
|
|
|
218
274
|
### Custom stream Engine
|
|
219
275
|
|
|
220
|
-
Discord Player by default uses
|
|
221
|
-
If you need to modify this behavior without touching extractors, you need to use `createStream` functionality of discord player.
|
|
222
|
-
Here's an example on how you can use **[play-dl](https://npmjs.com/package/play-dl)** to download youtube streams instead of using ytdl-core.
|
|
276
|
+
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.
|
|
223
277
|
|
|
224
278
|
```js
|
|
225
|
-
const
|
|
279
|
+
const fs = require('fs');
|
|
226
280
|
|
|
227
281
|
// other code
|
|
228
|
-
const queue = player.
|
|
282
|
+
const queue = player.nodes.create(..., {
|
|
229
283
|
...,
|
|
230
284
|
async onBeforeCreateStream(track, source, _queue) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// track here would be youtube track
|
|
234
|
-
return (await playdl.stream(track.url, { discordPlayerCompatibility : true })).stream;
|
|
235
|
-
// we must return readable stream or void (returning void means telling discord-player to look for default extractor)
|
|
285
|
+
if (track.title === 'some title') {
|
|
286
|
+
return fs.createReadStream('./playThisInstead.mp3');
|
|
236
287
|
}
|
|
237
288
|
}
|
|
238
289
|
});
|
|
239
290
|
```
|
|
240
291
|
|
|
241
|
-
|
|
242
|
-
streams. `source` here will be a
|
|
292
|
+
`\<GuildQueue>.onBeforeCreateStream` is called before actually downloading the stream. It is a different concept from extractors, where you are **just** downloading
|
|
293
|
+
streams. `source` here will be a track source. Streams from `onBeforeCreateStream` are then piped to `FFmpeg` and finally sent to Discord voice servers.
|