discord-player 6.0.0-dev.0 → 6.0.0-dev.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-present Androz
3
+ Copyright (c) 2020 Androz2091
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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)
@@ -7,8 +8,6 @@ Complete framework to facilitate music commands using **[discord.js](https://dis
7
8
  [![wakatime](https://wakatime.com/badge/github/Androz2091/discord-player.svg)](https://wakatime.com/badge/github/Androz2091/discord-player)
8
9
  [![CodeFactor](https://www.codefactor.io/repository/github/androz2091/discord-player/badge/v5)](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 FFmpeg or Avconv
27
- - 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)
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
- - Node Module (FFMPEG): **[https://npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
33
+ # or
34
+ $ npm install --save ytdl-core
35
+ ```
36
+
37
+ ### Install FFmpeg or Avconv
30
38
 
31
- - Avconv: **[https://libav.org/download](https://libav.org/download)**
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
- - Simple & easy to use 🤘
35
- - Beginner friendly 😱
36
- - Audio filters 🎸
37
- - Lightweight ☁️
38
- - Custom extractors support 🌌
39
- - Multiple sources support
40
- - Play in multiple servers at the same time 🚗
41
- - Does not inject anything to discord.js or your discord.js client 💉
42
- - 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 👑
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("@discordjs/rest");
52
- const { Routes } = require("discord-api-types/v9");
53
-
54
- const commands = [{
55
- name: "play",
56
- description: "Plays a song!",
57
- options: [
58
- {
59
- name: "query",
60
- type: "STRING",
61
- description: "The song you want to play",
62
- required: true
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: "9" }).setToken(process.env.DISCORD_TOKEN);
82
+ const rest = new REST({ version: '10' }).setToken('BOT_TOKEN');
68
83
 
69
84
  (async () => {
70
- try {
71
- console.log("Started refreshing application [/] commands.");
72
-
73
- await rest.put(
74
- Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
75
- { body: commands },
76
- );
77
-
78
- console.log("Successfully reloaded application [/] commands.");
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, Intents } = require("discord.js");
89
- const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_VOICE_STATES] });
90
- const { Player } = require("discord-player");
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 trackStart event so when a song will be played this message will be sent
96
- 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}**!`));
97
112
 
98
- client.once("ready", () => {
113
+ client.once('ready', () => {
99
114
  console.log("I'm ready !");
100
115
  });
101
116
 
102
- client.on("interactionCreate", async (interaction) => {
103
- if (!interaction.isCommand()) return;
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 === "play") {
108
- if (!interaction.member.voice.channelId) return await interaction.reply({ content: "You are not in a voice channel!", ephemeral: true });
109
- if (interaction.guild.me.voice.channelId && interaction.member.voice.channelId !== interaction.guild.me.voice.channelId) return await interaction.reply({ content: "You are not in my voice channel!", ephemeral: true });
110
- const query = interaction.options.get("query").value;
111
- const queue = player.createQueue(interaction.guild, {
112
- metadata: {
113
- channel: interaction.channel
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
- if (!queue.connection) await queue.connect(interaction.member.voice.channel);
120
- } catch {
121
- queue.destroy();
122
- 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 });
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(process.env.DISCORD_TOKEN);
146
+ client.login('BOT_TOKEN');
138
147
  ```
139
148
 
140
- ## Supported websites
149
+ ## Supported sources
150
+
151
+ By default, discord-player supports the following sources:
141
152
 
142
- By default, discord-player supports **YouTube**, **Spotify** and **SoundCloud** streams only.
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
- ### Optional dependencies
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
- #### [@discord-player/extractor](https://github.com/Snowflake107/discord-player-extractors) (optional)
175
+ ## Audio Filters
176
+
177
+ Discord Player supports various audio filters. There are 4 types of audio filters in discord-player.
149
178
 
150
- Optional package that adds support for `vimeo`, `reverbnation`, `facebook`, `attachment links` and `lyrics`.
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
- #### [@discord-player/downloader](https://github.com/DevSnowflake/discord-player-downloader) (optional)
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
- `@discord-player/downloader` is an optional package that brings support for +700 websites. The documentation is available [here](https://github.com/DevSnowflake/discord-player-downloader).
183
+ ```js
184
+ await queue.filters.ffmpeg.setFilters(['bassboost', 'nightcore']);
185
+ ```
156
186
 
157
- ## Examples of bots made with Discord Player
187
+ Note that there can be a delay between filters transition in this method.
158
188
 
159
- These bots are made by the community, they can help you build your own!
189
+ ##### Equalizer
160
190
 
161
- * **[Discord Music Bot](https://github.com/Androz2091/discord-music-bot)** by [Androz2091](https://github.com/Androz2091)
162
- * [Dodong](https://github.com/nizeic/Dodong) by [nizeic](https://github.com/nizeic)
163
- * [Musico](https://github.com/Whirl21/Musico) by [Whirl21](https://github.com/Whirl21)
164
- * [Eyesense-Music-Bot](https://github.com/naseif/Eyesense-Music-Bot) by [naseif](https://github.com/naseif)
165
- * [Music-bot](https://github.com/ZerioDev/Music-bot) by [ZerioDev](https://github.com/ZerioDev)
166
- * [AtlantaBot](https://github.com/Androz2091/AtlantaBot) by [Androz2091](https://github.com/Androz2091) (**outdated**)
167
- * [Discord-Music](https://github.com/inhydrox/discord-music) by [inhydrox](https://github.com/inhydrox) (**outdated**)
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
- ## Advanced
201
+ There is no delay between filter transition when using equalizer.
170
202
 
171
- ### Smooth Volume
203
+ ##### Biquad
172
204
 
173
- 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:
205
+ This filter provides digital biquad filterer to the player. To use this, you can do:
174
206
 
175
207
  ```js
176
- // CJS
177
- require("discord-player/smoothVolume");
208
+ import { BiquadFilterType } from 'discord-player';
178
209
 
179
- // ESM
180
- 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.
181
212
  ```
182
213
 
183
- > ⚠️ 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.
184
215
 
185
- ### Use cookies
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: "YOUR_YOUTUBE_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("https-proxy-agent");
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 = "http://user:pass@111.111.111.111:8080";
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 **[node-ytdl-core](https://github.com/fent/node-ytdl-core)** for youtube and some other extractors for other sources.
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 playdl = require("play-dl");
279
+ const fs = require('fs');
226
280
 
227
281
  // other code
228
- const queue = player.createQueue(..., {
282
+ const queue = player.nodes.create(..., {
229
283
  ...,
230
284
  async onBeforeCreateStream(track, source, _queue) {
231
- // only trap youtube source
232
- if (source === "youtube") {
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
- `<Queue>.onBeforeCreateStream` is called before actually downloading the stream. It is a different concept from extractors, where you are **just** downloading
242
- 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.