music-player-akumis

Complete framework to manage music commands using discord.js v12

Usage no npm install needed!

<script type="module">
  import musicPlayerAkumis from 'https://cdn.skypack.dev/music-player-akumis';
</script>

README

Music Player By Akumiś

downloadsBadge versionBadge patreonBadge

Note: this module uses recent discordjs features and requires discord.js version 12.

Music Player by Akumiś is a Node.js module that allows you to easily make Discord Music Bot with commands. You can customize everything, and everything is done to simplify your work without limiting you! Because it uses scraping, it doesn't require any API key!

Installation

npm install --save music-player-akumis

Install @discordjs/opus:

npm install --save @discordjs/opus

Install FFMPEG and everything is done!

Features

  1. Not complicated!
  2. A lot of commands to manage music!
  3. Free to use and edit!

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(),
settings = {
    prefix: "!",
    token: "Your Discord Token"
};

const { Player } = require("music-player-akumis");
const player = new Player(client);

client.player = player;

client.player.on('trackStart', (message, track) => message.channel.send(`Now playing ${track.title}...`))
client.on("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();
    if(command === "play"){
        client.player.play(message, args[0]);
    }
});

client.login(settings.token);

Methods overview

You need to init the guild queue using the play() function, then you are able to manage the queue and the music using the following functions. Click on a function name to get an example code and explanations.

Play a track

Check if a track is being played

Manage the queue

Manage music stream

Event messages

// Then add some messages that will be sent when the events will be triggered
client.player

// Send a message when a track starts
.on('trackStart', (message, track) => message.channel.send(`Now playing ${track.title}...`))

// Send a message when something is added to the queue
.on('trackAdd', (message, queue, track) => message.channel.send(`${track.title} has been added to the queue!`))
.on('playlistAdd', (message, queue, playlist) => message.channel.send(`${playlist.title} has been added to the queue (${playlist.tracks.length} songs)!`))

// Send messages to format search results
.on('searchResults', (message, query, tracks) => {

    const embed = new Discord.MessageEmbed()
    .setAuthor(`Here are your search results for ${query}!`)
    .setDescription(tracks.map((t, i) => `${i}. ${t.title}`))
    .setFooter('Send the number of the song you want to play!')
    message.channel.send(embed);

})
.on('searchInvalidResponse', (message, query, tracks, content, collector) => {

    if (content === 'cancel') {
        collector.stop()
        return message.channel.send('Search cancelled!')
    }

    message.channel.send(`You must send a valid number between 1 and ${tracks.length}!`)

})
.on('searchCancel', (message, query, tracks) => message.channel.send('You did not provide a valid response... Please send the command again!'))
.on('noResults', (message, query) => message.channel.send(`No results found on YouTube for ${query}!`))

// Send a message when the music is stopped
.on('queueEnd', (message, queue) => message.channel.send('Music stopped as there is no more music in the queue!'))
.on('channelEmpty', (message, queue) => message.channel.send('Music stopped as there is no more member in the voice channel!'))
.on('botDisconnect', (message) => message.channel.send('Music stopped as I have been disconnected from the channel!'))

// Error handling
.on('error', (error, message) => {
    switch(error){
        case 'NotPlaying':
            message.channel.send('There is no music being played on this server!')
            break;
        case 'NotConnected':
            message.channel.send('You are not connected in any voice channel!')
            break;
        case 'UnableToJoin':
            message.channel.send('I am not able to join your voice channel, please check my permissions!')
            break;
        case 'LiveVideo':
            message.channel.send('YouTube lives are not supported!')
            break;
        default:
            message.channel.send(`Something went wrong... Error: ${error}`)
    }
})