discord-player 5.4.1-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/README.md +162 -115
- package/dist/index.d.ts +445 -148
- package/dist/index.js +1212 -336
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1197 -325
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -12
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)
|
|
@@ -18,27 +19,40 @@ $ npm install --save discord-player
|
|
|
18
19
|
### Install **[@discordjs/opus](https://npmjs.com/package/@discordjs/opus)**
|
|
19
20
|
|
|
20
21
|
```sh
|
|
21
|
-
$ 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
|
|
22
26
|
```
|
|
23
27
|
|
|
24
|
-
### Install
|
|
25
|
-
- Official FFMPEG Website: **[https://www.ffmpeg.org/download.html](https://www.ffmpeg.org/download.html)**
|
|
28
|
+
### Install streaming library (if you want to play from youtube)
|
|
26
29
|
|
|
27
|
-
|
|
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
|
|
38
|
+
|
|
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)**
|
|
30
42
|
|
|
31
43
|
# Features
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
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 👑
|
|
42
56
|
|
|
43
57
|
## [Documentation](https://discord-player.js.org)
|
|
44
58
|
|
|
@@ -47,166 +61,204 @@ $ npm install --save @discordjs/opus
|
|
|
47
61
|
First of all, you will need to register slash commands:
|
|
48
62
|
|
|
49
63
|
```js
|
|
50
|
-
const { REST } = require(
|
|
51
|
-
const { Routes, ApplicationCommandOptionType } = require(
|
|
64
|
+
const { REST } = require('@discordjs/rest');
|
|
65
|
+
const { Routes, ApplicationCommandOptionType } = require('discord.js');
|
|
52
66
|
|
|
53
67
|
const commands = [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
}
|
|
66
80
|
];
|
|
67
81
|
|
|
68
|
-
const rest = new REST({ version:
|
|
82
|
+
const rest = new REST({ version: '10' }).setToken('BOT_TOKEN');
|
|
69
83
|
|
|
70
84
|
(async () => {
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
try {
|
|
86
|
+
console.log('Started refreshing application [/] commands.');
|
|
73
87
|
|
|
74
|
-
|
|
88
|
+
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
|
|
75
89
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
90
|
+
console.log('Successfully reloaded application [/] commands.');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error(error);
|
|
93
|
+
}
|
|
80
94
|
})();
|
|
81
95
|
```
|
|
82
96
|
|
|
83
97
|
Now you can implement your bot's logic:
|
|
84
98
|
|
|
85
99
|
```js
|
|
86
|
-
const { Client } = require(
|
|
100
|
+
const { Client } = require('discord.js');
|
|
87
101
|
const client = new Discord.Client({
|
|
88
|
-
intents: [
|
|
89
|
-
"Guilds",
|
|
90
|
-
"GuildVoiceStates"
|
|
91
|
-
]
|
|
102
|
+
intents: ['Guilds', 'GuildVoiceStates']
|
|
92
103
|
});
|
|
93
|
-
const { Player } = require(
|
|
104
|
+
const { Player } = require('discord-player');
|
|
94
105
|
|
|
95
106
|
// Create a new Player (you don't need any API Key)
|
|
96
107
|
const player = new Player(client);
|
|
97
108
|
|
|
98
|
-
// add the
|
|
99
|
-
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}**!`));
|
|
100
112
|
|
|
101
|
-
client.once(
|
|
113
|
+
client.once('ready', () => {
|
|
102
114
|
console.log("I'm ready !");
|
|
103
115
|
});
|
|
104
116
|
|
|
105
|
-
client.on(
|
|
117
|
+
client.on('interactionCreate', async (interaction) => {
|
|
106
118
|
if (!interaction.isChatInputCommand()) return;
|
|
107
119
|
|
|
108
120
|
// /play track:Despacito
|
|
109
121
|
// will play "Despacito" in the voice channel
|
|
110
|
-
if (interaction.commandName ===
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// 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
|
+
|
|
121
130
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 });
|
|
126
142
|
}
|
|
127
|
-
|
|
128
|
-
await interaction.deferReply();
|
|
129
|
-
const track = await player.search(query, {
|
|
130
|
-
requestedBy: interaction.user
|
|
131
|
-
}).then(x => x.tracks[0]);
|
|
132
|
-
if (!track) return await interaction.followUp({ content: `❌ | Track **${query}** not found!` });
|
|
133
|
-
|
|
134
|
-
queue.play(track);
|
|
135
|
-
|
|
136
|
-
return await interaction.followUp({ content: `⏱️ | Loading track **${track.title}**!` });
|
|
137
143
|
}
|
|
138
144
|
});
|
|
139
145
|
|
|
140
|
-
client.login(
|
|
146
|
+
client.login('BOT_TOKEN');
|
|
141
147
|
```
|
|
142
148
|
|
|
143
|
-
## Supported
|
|
149
|
+
## Supported sources
|
|
150
|
+
|
|
151
|
+
By default, discord-player supports the following sources:
|
|
152
|
+
|
|
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
|
|
160
|
+
|
|
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:
|
|
144
163
|
|
|
145
|
-
|
|
164
|
+
```js
|
|
165
|
+
const result = await player.search(query, {
|
|
166
|
+
// always use soundcloud extractor
|
|
167
|
+
searchEngine: 'ext:com.discord-player.soundcloudextractor'
|
|
168
|
+
});
|
|
169
|
+
```
|
|
146
170
|
|
|
147
|
-
###
|
|
171
|
+
### Adding more sources
|
|
148
172
|
|
|
149
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.
|
|
150
174
|
|
|
151
|
-
|
|
175
|
+
## Audio Filters
|
|
152
176
|
|
|
153
|
-
|
|
154
|
-
You just need to install it using `npm i --save @discord-player/extractor` (discord-player will automatically detect and use it).
|
|
177
|
+
Discord Player supports various audio filters. There are 4 types of audio filters in discord-player.
|
|
155
178
|
|
|
156
|
-
|
|
179
|
+
##### FFmpeg
|
|
157
180
|
|
|
158
|
-
|
|
181
|
+
The most common and powerful method is FFmpeg. It supports a lot of audio filters. To set ffmpeg filter, you can do:
|
|
159
182
|
|
|
160
|
-
|
|
183
|
+
```js
|
|
184
|
+
await queue.filters.ffmpeg.setFilters(['bassboost', 'nightcore']);
|
|
185
|
+
```
|
|
161
186
|
|
|
162
|
-
|
|
187
|
+
Note that there can be a delay between filters transition in this method.
|
|
163
188
|
|
|
164
|
-
|
|
165
|
-
* [Dodong](https://github.com/nizeic/Dodong) by [nizeic](https://github.com/nizeic)
|
|
166
|
-
* [Musico](https://github.com/Whirl21/Musico) by [Whirl21](https://github.com/Whirl21)
|
|
167
|
-
* [Melody](https://github.com/NerdyTechy/Melody) by [NerdyTechy](https://github.com/NerdyTechy)
|
|
168
|
-
* [Eyesense-Music-Bot](https://github.com/naseif/Eyesense-Music-Bot) by [naseif](https://github.com/naseif)
|
|
169
|
-
* [Music-bot](https://github.com/ZerioDev/Music-bot) by [ZerioDev](https://github.com/ZerioDev)
|
|
170
|
-
* [AtlantaBot](https://github.com/Androz2091/AtlantaBot) by [Androz2091](https://github.com/Androz2091) (**outdated**)
|
|
171
|
-
* [Discord-Music](https://github.com/inhydrox/discord-music) by [inhydrox](https://github.com/inhydrox) (**outdated**)
|
|
189
|
+
##### Equalizer
|
|
172
190
|
|
|
173
|
-
|
|
191
|
+
This equalizer is very similar to Lavalink's 15 Band Equalizer. To use this, you can do:
|
|
174
192
|
|
|
175
|
-
|
|
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
|
+
```
|
|
200
|
+
|
|
201
|
+
There is no delay between filter transition when using equalizer.
|
|
176
202
|
|
|
177
|
-
|
|
203
|
+
##### Biquad
|
|
204
|
+
|
|
205
|
+
This filter provides digital biquad filterer to the player. To use this, you can do:
|
|
178
206
|
|
|
179
207
|
```js
|
|
180
|
-
|
|
181
|
-
require("discord-player/smoothVolume");
|
|
208
|
+
import { BiquadFilterType } from 'discord-player';
|
|
182
209
|
|
|
183
|
-
|
|
184
|
-
|
|
210
|
+
queue.filters.biquad.setFilter(BiquadFilterType.LowPass);
|
|
211
|
+
// similarly, you can use other filters such as HighPass, BandPass, Notch, PeakEQ, LowShelf, HighShelf, etc.
|
|
185
212
|
```
|
|
186
213
|
|
|
187
|
-
|
|
214
|
+
There is no delay between filter transition when using biquad filters.
|
|
215
|
+
|
|
216
|
+
#### Mini Audio Filters
|
|
188
217
|
|
|
189
|
-
|
|
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
|
|
190
240
|
|
|
191
241
|
```js
|
|
192
242
|
const player = new Player(client, {
|
|
193
243
|
ytdlOptions: {
|
|
194
244
|
requestOptions: {
|
|
195
245
|
headers: {
|
|
196
|
-
cookie:
|
|
246
|
+
cookie: 'YOUR_YOUTUBE_COOKIE'
|
|
197
247
|
}
|
|
198
248
|
}
|
|
199
249
|
}
|
|
200
250
|
});
|
|
201
251
|
```
|
|
202
252
|
|
|
253
|
+
> Note: the above option is only used when ytdl-core is being used.
|
|
254
|
+
|
|
203
255
|
### Use custom proxies
|
|
204
256
|
|
|
205
257
|
```js
|
|
206
|
-
const HttpsProxyAgent = require(
|
|
258
|
+
const HttpsProxyAgent = require('https-proxy-agent');
|
|
207
259
|
|
|
208
260
|
// Remove "user:pass@" if you don't need to authenticate to your proxy.
|
|
209
|
-
const proxy =
|
|
261
|
+
const proxy = 'http://user:pass@111.111.111.111:8080';
|
|
210
262
|
const agent = HttpsProxyAgent(proxy);
|
|
211
263
|
|
|
212
264
|
const player = new Player(client, {
|
|
@@ -221,26 +273,21 @@ const player = new Player(client, {
|
|
|
221
273
|
|
|
222
274
|
### Custom stream Engine
|
|
223
275
|
|
|
224
|
-
Discord Player by default uses
|
|
225
|
-
If you need to modify this behavior without touching extractors, you need to use `createStream` functionality of discord player.
|
|
226
|
-
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.
|
|
227
277
|
|
|
228
278
|
```js
|
|
229
|
-
const
|
|
279
|
+
const fs = require('fs');
|
|
230
280
|
|
|
231
281
|
// other code
|
|
232
|
-
const queue = player.
|
|
282
|
+
const queue = player.nodes.create(..., {
|
|
233
283
|
...,
|
|
234
284
|
async onBeforeCreateStream(track, source, _queue) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
// track here would be youtube track
|
|
238
|
-
return (await playdl.stream(track.url, { discordPlayerCompatibility : true })).stream;
|
|
239
|
-
// 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');
|
|
240
287
|
}
|
|
241
288
|
}
|
|
242
289
|
});
|
|
243
290
|
```
|
|
244
291
|
|
|
245
|
-
|
|
246
|
-
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.
|