discord-player-play-dl/README.md

162 lines
5.3 KiB
Markdown
Raw Normal View History

2021-04-04 21:34:41 +05:00
# Discord Player
Complete framework to facilitate music commands using **[discord.js](https://discord.js.org)**.
[![downloadsBadge](https://img.shields.io/npm/dt/discord-player?style=for-the-badge)](https://npmjs.com/discord-player)
[![versionBadge](https://img.shields.io/npm/v/discord-player?style=for-the-badge)](https://npmjs.com/discord-player)
2021-04-25 14:23:45 +05:00
[![discordBadge](https://img.shields.io/discord/558328638911545423?style=for-the-badge&color=7289da)](https://androz2091.fr/discord)
2021-04-04 21:34:41 +05:00
2021-05-01 12:50:14 +05:00
> V5 WIP
2021-04-04 21:34:41 +05:00
## Installation
### Install **[discord-player](https://npmjs.com/package/discord-player)**
```sh
$ npm install --save discord-player
```
### Install **[@discordjs/opus](https://npmjs.com/package/@discordjs/opus)**
```sh
$ npm install --save @discordjs/opus
```
### Install FFmpeg or Avconv
- Official FFMPEG Website: **[https://www.ffmpeg.org/download.html](https://www.ffmpeg.org/download.html)**
- Node Module (FFMPEG): **[https://npmjs.com/package/ffmpeg-static](https://npmjs.com/package/ffmpeg-static)**
- Avconv: **[https://libav.org/download](https://libav.org/download)**
# Features
- Simple & easy to use 🤘
- Beginner friendly 😱
- Audio filters 🎸
- Lightweight 🛬
2021-04-10 11:14:50 +05:00
- Custom extractors support 🌌
- Lyrics 📃
2021-04-10 22:52:48 +05:00
- Multiple sources support ✌
- Play in multiple servers at the same time 🚗
2021-04-04 21:34:41 +05:00
2021-04-18 22:20:12 +05:00
## [Documentation](https://discord-player.js.org)
## Getting Started
Here is the code you will need to get started with discord-player. Then, you will be able to use `client.player` everywhere in your code!
```js
const Discord = require("discord.js"),
2021-06-18 00:09:02 +05:00
client = new Discord.Client({ intents: ["GUILD_VOICE_STATES", "GUILD_MESSAGES", "GUILDS"] }),
2021-04-18 22:20:12 +05:00
settings = {
prefix: "!",
token: "Your Discord Token"
};
2021-06-18 00:09:02 +05:00
const { Player, QueryType } = require("discord-player");
2021-04-18 22:20:12 +05:00
// Create a new Player (you don't need any API Key)
const player = new Player(client);
// To easily access the player
client.player = player;
// add the trackStart event so when a song will be played this message will be sent
2021-06-18 00:09:02 +05:00
client.player.on("trackStart", (queue, track) => queue.metadata.channel.send(`Now playing ${track.title}...`))
2021-04-18 22:20:12 +05:00
client.once("ready", () => {
console.log("I'm ready !");
});
client.on("message", async (message) => {
const args = message.content.slice(settings.prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
// !play Despacito
// will play "Despacito" in the voice channel
2021-06-18 00:09:02 +05:00
if (command === "play") {
if (!message.member.voice.channel) return void message.reply("You are not in a voice channel!");
if (message.guild.me.voice.channel && message.member.voice.channelID !== message.guild.me.voice.channelID) return void message.reply("You are not in my voice channel!");
const queue = client.player.createQueue(message.guild, {
metadata: message
});
// verify vc connection
try {
if (!queue.connection) await queue.connect(message.member.voice.channel);
} catch {
queue.destroy();
return void message.reply("Could not join your voice channel!");
}
const track = await client.player.search(args[0], {
searchEngine: QueryType.YOUTUBE_SEARCH
}).then(x => x.tracks[1]);
if (!track) return void message.reply("Track not found!");
queue.play(track);
2021-04-18 22:20:12 +05:00
}
});
client.login(settings.token);
```
2021-04-19 18:59:17 +05:00
## Supported websites
By default, discord-player supports **YouTube**, **Spotify** and **SoundCloud** streams only.
2021-04-19 19:01:36 +05:00
### Optional dependencies
2021-04-19 18:59:17 +05:00
2021-04-19 19:01:36 +05:00
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.
2021-04-19 18:59:17 +05:00
2021-04-19 19:01:36 +05:00
#### [@discord-player/extractor](https://github.com/Snowflake107/discord-player-extractors) (optional)
2021-04-19 18:59:17 +05:00
2021-04-19 19:01:36 +05:00
Optional package that adds support for `vimeo`, `reverbnation`, `facebook`, `attachment links` and `lyrics`.
2021-04-19 19:46:58 +05:00
You just need to install it using `npm i --save @discord-player/extractor` (discord-player will automatically detect and use it).
2021-04-19 18:59:17 +05:00
2021-04-19 19:01:36 +05:00
#### [@discord-player/downloader](https://github.com/DevSnowflake/discord-player-downloader) (optional)
2021-04-19 18:59:17 +05:00
`@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).
## Examples of bots made with Discord Player
These bots are made by the community, they can help you build your own!
* [AtlantaBot](https://github.com/Androz2091/AtlantaBot) by [Androz2091](https://github.com/Androz2091)
* [Discord-Music](https://github.com/inhydrox/discord-music) by [inhydrox](https://github.com/inhydrox)
* [Music-bot](https://github.com/ZerioDev/Music-bot) by [ZerioDev](https://github.com/ZerioDev)
## Advanced
2021-04-19 18:59:17 +05:00
### Use cookies
2021-04-18 22:20:12 +05:00
```js
const player = new Player(client, {
ytdlDownloadOptions: {
requestOptions: {
headers: {
cookie: "YOUR_YOUTUBE_COOKIE"
}
}
}
});
```
### Use custom proxies
2021-04-18 22:20:12 +05:00
```js
const HttpsProxyAgent = require("https-proxy-agent");
// Remove "user:pass@" if you don't need to authenticate to your proxy.
const proxy = "http://user:pass@111.111.111.111:8080";
const agent = HttpsProxyAgent(proxy);
const player = new Player(client, {
ytdlDownloadOptions: {
requestOptions: { agent }
}
});
```