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 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
  [![downloadsBadge](https://img.shields.io/npm/dt/discord-player?style=for-the-badge)](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 FFmpeg or Avconv
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
- - Node Module (FFMPEG): **[https://npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
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
- - Avconv: **[https://libav.org/download](https://libav.org/download)**
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
- - Simple & easy to use 🤘
33
- - Beginner friendly 😱
34
- - Audio filters 🎸
35
- - Lavalink compatible 15 band equalizer 🎚️
36
- - Lightweight ☁️
37
- - Custom extractors support 🌌
38
- - Multiple sources support ✌
39
- - Play in multiple servers at the same time 🚗
40
- - Does not inject anything to discord.js or your discord.js client 💉
41
- - Allows you to have full control over what is going to be streamed 👑
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("@discordjs/rest");
51
- const { Routes, ApplicationCommandOptionType } = require("discord.js");
64
+ const { REST } = require('@discordjs/rest');
65
+ const { Routes, ApplicationCommandOptionType } = require('discord.js');
52
66
 
53
67
  const commands = [
54
- {
55
- name: "play",
56
- description: "Plays a song!",
57
- options: [
58
- {
59
- name: "query",
60
- type: ApplicationCommandOptionType.String,
61
- description: "The song you want to play",
62
- required: true
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: "10" }).setToken("BOT_TOKEN");
82
+ const rest = new REST({ version: '10' }).setToken('BOT_TOKEN');
69
83
 
70
84
  (async () => {
71
- try {
72
- console.log("Started refreshing application [/] commands.");
85
+ try {
86
+ console.log('Started refreshing application [/] commands.');
73
87
 
74
- await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
88
+ await rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands });
75
89
 
76
- console.log("Successfully reloaded application [/] commands.");
77
- } catch(error) {
78
- console.error(error);
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("discord.js");
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("discord-player");
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 trackStart event so when a song will be played this message will be sent
99
- player.on("trackStart", (queue, track) => queue.metadata.channel.send(`🎶 | Now playing **${track.title}**!`))
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("ready", () => {
113
+ client.once('ready', () => {
102
114
  console.log("I'm ready !");
103
115
  });
104
116
 
105
- client.on("interactionCreate", async (interaction) => {
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 === "play") {
111
- if (!interaction.member.voice.channelId) return await interaction.reply({ content: "You are not in a voice channel!", ephemeral: true });
112
- if (interaction.guild.members.me.voice.channelId && interaction.member.voice.channelId !== interaction.guild.members.me.voice.channelId) return await interaction.reply({ content: "You are not in my voice channel!", ephemeral: true });
113
- const query = interaction.options.getString("query");
114
- const queue = player.createQueue(interaction.guild, {
115
- metadata: {
116
- channel: interaction.channel
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
- if (!queue.connection) await queue.connect(interaction.member.voice.channel);
123
- } catch {
124
- queue.destroy();
125
- return await interaction.reply({ content: "Could not join your voice channel!", ephemeral: true });
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("BOT_TOKEN");
146
+ client.login('BOT_TOKEN');
141
147
  ```
142
148
 
143
- ## Supported websites
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
- By default, discord-player supports **YouTube**, **Spotify** and **SoundCloud** streams only.
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
- ### Optional dependencies
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
- #### [@discord-player/extractor](https://github.com/DevAndromeda/discord-player-extractors) (optional)
175
+ ## Audio Filters
152
176
 
153
- Optional package that adds support for `vimeo`, `reverbnation`, `facebook`, `attachment links` and `lyrics`.
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
- #### [@discord-player/downloader](https://github.com/DevAndromeda/discord-player-downloader) (optional)
179
+ ##### FFmpeg
157
180
 
158
- `@discord-player/downloader` is an optional package that brings support for +700 websites. The documentation is available [here](https://github.com/DevAndromeda/discord-player-downloader).
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
- ## Examples of bots made with Discord Player
183
+ ```js
184
+ await queue.filters.ffmpeg.setFilters(['bassboost', 'nightcore']);
185
+ ```
161
186
 
162
- These bots are made by the community, they can help you build your own!
187
+ Note that there can be a delay between filters transition in this method.
163
188
 
164
- * **[Discord Music Bot](https://github.com/Androz2091/discord-music-bot)** by [Androz2091](https://github.com/Androz2091)
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
- ## Advanced
191
+ This equalizer is very similar to Lavalink's 15 Band Equalizer. To use this, you can do:
174
192
 
175
- ### Smooth Volume
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
- Discord Player will by default try to implement this. If smooth volume does not work, you need to add this line at the top of your main file:
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
- // CJS
181
- require("discord-player/smoothVolume");
208
+ import { BiquadFilterType } from 'discord-player';
182
209
 
183
- // ESM
184
- import "discord-player/smoothVolume"
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
- > ⚠️ Make sure that line is situated at the **TOP** of your **main** file.
214
+ There is no delay between filter transition when using biquad filters.
215
+
216
+ #### Mini Audio Filters
188
217
 
189
- ### Use cookies
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: "YOUR_YOUTUBE_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("https-proxy-agent");
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 = "http://user:pass@111.111.111.111:8080";
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 **[node-ytdl-core](https://github.com/fent/node-ytdl-core)** for youtube and some other extractors for other sources.
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 playdl = require("play-dl");
279
+ const fs = require('fs');
230
280
 
231
281
  // other code
232
- const queue = player.createQueue(..., {
282
+ const queue = player.nodes.create(..., {
233
283
  ...,
234
284
  async onBeforeCreateStream(track, source, _queue) {
235
- // only trap youtube source
236
- if (source === "youtube") {
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
- `<Queue>.onBeforeCreateStream` is called before actually downloading the stream. It is a different concept from extractors, where you are **just** downloading
246
- streams. `source` here will be a video source. Streams from `onBeforeCreateStream` are then piped to `FFmpeg` and finally sent to Discord voice servers.
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.