No description
Find a file
2021-06-20 20:45:19 +05:45
.github action docs: generate v5 2021-06-20 20:08:12 +05:45
docs documentation 2021-06-20 20:45:19 +05:45
example documentation 2021-06-20 20:45:19 +05:45
src documentation 2021-06-20 20:45:19 +05:45
.gitattributes spotify 2021-05-10 10:56:28 +05:45
.gitignore dev 2021-06-19 18:01:01 +05:45
.npmignore fix docs 2021-04-21 10:53:33 +05:45
.prettierrc basic slash commands bot 2021-06-13 13:51:19 +05:45
CODE_OF_CONDUCT.md CODE_OF_CONDUCT 2021-04-18 23:29:12 +05:45
CONTRIBUTING.md some changes 2021-04-21 16:32:14 +05:45
jsdoc.json fix docs 2021-04-21 10:53:33 +05:45
LICENSE merge master 2021-04-18 23:20:18 +05:45
package.json documentation 2021-06-20 20:31:57 +05:45
README.md wakatime stats 2021-06-20 14:49:34 +05:45
tsconfig.json feat: documentation 2021-06-20 20:07:09 +05:45
tslint.json format 2021-04-06 18:43:46 +05:45

Discord Player

Complete framework to facilitate music commands using discord.js.

downloadsBadge versionBadge discordBadge wakatime

V5 WIP

Installation

Install discord-player

$ npm install --save discord-player

Install @discordjs/opus

$ npm install --save @discordjs/opus

Install FFmpeg or Avconv

Features

  • Simple & easy to use 🤘
  • Beginner friendly 😱
  • Audio filters 🎸
  • Lightweight 🛬
  • Custom extractors support 🌌
  • Lyrics 📃
  • Multiple sources support ✌
  • Play in multiple servers at the same time 🚗

Documentation

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!

const Discord = require("discord.js"),
client = new Discord.Client({ intents: ["GUILD_VOICE_STATES", "GUILD_MESSAGES", "GUILDS"] }),
settings = {
    prefix: "!",
    token: "Your Discord Token"
};

const { Player, QueryType } = require("discord-player");

// 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
client.player.on("trackStart", (queue, track) => queue.metadata.channel.send(`Now playing ${track.title}...`))

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
    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);
    }

});

client.login(settings.token);

Supported websites

By default, discord-player supports YouTube, Spotify and SoundCloud streams only.

Optional dependencies

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.

@discord-player/extractor (optional)

Optional package that adds support for vimeo, reverbnation, facebook, attachment links and lyrics. You just need to install it using npm i --save @discord-player/extractor (discord-player will automatically detect and use it).

@discord-player/downloader (optional)

@discord-player/downloader is an optional package that brings support for +700 websites. The documentation is available here.

Examples of bots made with Discord Player

These bots are made by the community, they can help you build your own!

Advanced

Use cookies

const player = new Player(client, {
    ytdlOptions: {
        requestOptions: {
            headers: {
                cookie: "YOUR_YOUTUBE_COOKIE"
            }
        }
    }
});

Use custom proxies

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, {
    ytdlOptions: {
        requestOptions: { agent }
    }
});