Coder Social home page Coder Social logo

notghex / discord-player Goto Github PK

View Code? Open in Web Editor NEW

This project forked from androz2091/discord-player

0.0 0.0 0.0 5.82 MB

๐ŸŽง Complete framework to simplify the implementation of music commands using discords.js v14

Home Page: https://discord-player.js.org/

License: MIT License

Shell 0.02% JavaScript 1.34% TypeScript 98.60% CSS 0.04%

discord-player's Introduction

Discord Player

Discord Player is a powerful framework for JavaScript and TypeScript, built on top of @discord.js/voice library. It provides easy set of customizable tools to develop Discord Music bots.

downloadsBadge versionBadge discordBadge

Why Discord Player?

  • Beginner friendly, easy to understand
  • TypeScript support
  • Supports audio player sharing
  • Quick and easy to set up
  • Wide range of player management features
  • 64+ built-in audio filter presets
  • Highly customizable
  • Automatic queue management
  • Query caching support
  • Wide range of extendable sources via Extractors API
  • Object oriented
  • Built in stats tracker

Installation

Before you start

Discord Player requires Discord.js 14.0 or higher. PLease make sure you have a compatible version using npm list discord.js in your terminal. If you're using an earlier version please update it. The Discord.JS Guide has resources to help with that.

Main Library

$ yarn add discord-player # main library
$ yarn add @discord-player/extractor # extractors provider

Discord Player recognizes @discord-player/extractor and loads it automatically by default.

Opus Library

Discord Player is a high level framework for Discord VoIP. Discord only accepts opus packets, thus you need to install opus library. You can install any of these:

$ yarn add @discordjs/opus
# or
$ yarn add opusscript

FFmpeg or Avconv

FFmpeg or Avconv is required for media transcoding. You can get it from https://ffmpeg.org or by installing it from npm (ffmpeg-static is not recommended):

$ yarn add ffmpeg-static

You can get avconv from https://libav.org/download.

Streaming Library

You also need to install streaming library if you want to add support for youtube playback. You can install one of these libraries:

$ yarn add ytdl-core
# or
$ yarn add play-dl
# or
$ yarn add @distube/ytdl-core

Done with all these? Let's write a simple music bot then.

Setup

Let's create a master player instance.

const { Player } = require('discord-player');
const client = new Discord.Client({
    // Make sure you have 'GuildVoiceStates' intent enabled
    intents: ['GuildVoiceStates' /* Other intents */]
});

// this is the entrypoint for discord-player based application
const player = new Player(client);

Did You Know? Discord Player is by default a singleton.

Now, let's add some event listeners:

// this event is emitted whenever discord-player starts to play a track
player.events.on('playerStart', (queue, track) => {
    // we will later define queue.metadata object while creating the queue
    queue.metadata.channel.send(`Started playing **${track.title}**!`);
});

Let's write the command part. You can define the command as you desire. We will only check the command handler part:

async function execute(interaction) {
    const channel = interaction.message.member.voice.channel;
    if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
    const query = interaction.options.getString('query', true); // we need input/query to play

    // let's defer the interaction as things can take time to process
    await interaction.deferReply();

    try {
        const { track } = await player.play(channel, query, {
            nodeOptions: {
                // nodeOptions are the options for guild node (aka your queue in simple word)
                metadata: interaction // we can access this metadata object using queue.metadata later on
            }
        });

        return interaction.followUp(`**${track.title}** enqueued!`);
    } catch (e) {
        // let's return error if something failed
        return interaction.followUp(`Something went wrong: ${e}`);
    }
}

That's all it takes to build your own music bot.

Check out the Documentation for more info.

Community Resources

A curated list of resources (such as open source music bots, extractors, etc.) built by Discord Player community. https://discord-player.js.org/docs/guides/community-resources

discord-player's People

Contributors

416rehman avatar abish-desu avatar aiko-chan-ai avatar androz2091 avatar casperiv0 avatar crocross avatar dependabot-preview[bot] avatar dependabot[bot] avatar dongsu8142 avatar ewox07 avatar febkosq8 avatar imyanice avatar itsauric avatar klairm avatar maxtechnics avatar nerdytechy avatar notghex avatar sayuriu avatar simonleclere avatar skick1234 avatar tapshts avatar tasooneasia avatar thaddeuskkr avatar thomasthebro1 avatar tjrgg avatar toledosdl avatar twlite avatar umutdeveci avatar whirlxd avatar zackradisic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.