@koenie06/discord.js-music
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

NPM info

Features

  • Customizable and easy to use.
  • Supports Youtube, Spotify, Soundcloud and much more..! (Watch out! Only some spotify songs are working, I am working on it..)
  • Automaticly makes a server queue.
  • Has been made with @discordjs/voice.
  • Supports youtube playlists. (More in the future..)

📥 Installation

Wait! Before you install, you need..

  • Node.js

  • Discord.js v13+

After this, you can finally install the package with:

$ npm install @koenie06/discord.js-music

🔎 Functions

There are a lot of functions, that are probably useful to know.

Music:

  • .play() - Plays the given music in the given channel.
  • .stop() - Stops the music whenever it is playing.
  • .skip() - Skips the current playing song.
  • .pause() - Pauses the current playing song.
  • .resume() - Resumes the playing song whenever it is paused.
  • .repeat() - Repeats the playing song forever, until it is turned off.
  • .volume() - Changes the music volume.
  • .jump() - Jumps to a the given queue number song.
  • .getQueue() - Returns a Array of queued songs.
  • .removeQueue() - Removes the given queue song number from the queue.

Checks:

Events:

  • playSong - Runs whenever a new song started playing.
  • addSong - Runs whenever a song has been added to the queue.
  • playList - Runs whenever a new song of a playlist started playing.
  • addList - Runs whenever a playlist has been added to the queue.
  • finish - Runs whenever all the queued songs are played.

🎹 Play

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'play') {

            /*
             * This function requires 3 options:
             * 1) Interaction. The interaction you got from the 'interactionCreate' event.
             * 2) Channel. The Voice Channel where the music is supposed to be played in.
             * 3) Song. A song name/URL that needs to be played.
            */

           const channel = interaction.member.voice.channel;
           const song = interaction.options.getString('song');

           music.play({
               interaction: interaction,
               channel: channel,
               song: song
           });
        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

Stop

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'stop') music.stop({ interaction: interaction });
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

Skip

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'skip') music.skip({ interaction: interaction });
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

Pause

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'pause') music.pause({ interaction: interaction });
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

Resume

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'resume') music.resume({ interaction: interaction });
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🔁 Repeat

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'repeat') {

            /* 
             * Use 'true' to set the song on repeat.
             * Use 'false' to turn the repeat mode off when it is on.
            */

            const OnOrOff = interaction.options.getBoolean('onoff');

            music.repeat({
                interaction: interaction,
                value: onOrOff
            });
            
        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🔊 Volume

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'volume') {
            
            /*
             * Volume option needs to be an Integer and can't be higher than 100.
            */
            
            const volume = interaction.options.getInteger('volume');
            
            music.volume({
                interaction: interaction,
                volume: volume
            });
        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🦘 Jump

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'jump') {

            /*
             * Number option needs to be an Integer and has to be a valid queue number.
            */

            const number = interaction.options.getInteger('number');

            music.jump({
                interaction: interaction,
                number: number
            });
        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🚶🚶 getQueue

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'getqueue') console.log(await(music.getQueue({ interaction: interaction })));
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

removeQueue

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'removequeue') {

            /*
             * Number option needs to be an Integer and has to be a valid queue number.
            */

            const number = interaction.options.getInteger('number');

            music.removeQueue({
                interaction: interaction,
                number: number 
            });

        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

isConnected

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'isconnected') {

            /*
             * This function returns a boolean whenever it is connected or not.
             * 'true' means that it is connected to a VoiceChannel.
             * 'false' means that it isn't connected to any VoiceChannel.
            */

            const isConnected = await music.isConnected({ interaction: interaction });
    
            interaction.reply({ content: isConnected === true ? 'I am connected!' : 'Welp.. I am not connected to any channel here.' });

        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

isPaused

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'ispaused') {

            /*
             * This function returns a boolean whenever it is paused or not.
             * 'true' means that the playing song is paused.
             * 'false' means that the playing song is still playing.
            */

            const isPaused = await music.isPaused({ interaction: interaction });
    
            interaction.reply({ content: isPaused === true ? 'I am waiting for you to resume..' : 'Yes yes, i am still playing music!' });

        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

isResumed

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'isresumed') {

            /*
             * This function returns a boolean whenever it is resumed or not.
             * 'true' means that the playing song is still playing.
             * 'false' means that the song is paused.
            */

            const isResumed = await music.isResumed({ interaction: interaction });
    
            interaction.reply({ content: isResumed === true ? 'Ofcourse i am still playing music!' : 'Sadly enough.. I got paused.' });

        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

isRepeated

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.GUILD_VOICE_STATES] });

/* This code will run when the client receives a interaction */
client.on('interactionCreate', async (interaction) => {
    if(interaction.isCommand()) {
        if(interaction.commandName === 'isrepeated') {

            /*
             * This function returns a boolean whenever it is resumed or not.
             * 'true' means that the playing song is on repeat.
             * 'false' means that the queue is just playing normally.
            */

            const isRepeated = await music.isRepeated({ interaction: interaction });
    
            interaction.reply({ content: isRepeated === true ? 'This song is in a infinite loop!' : 'Just playing the queue normally.' });

        };
    };
});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🎵 Events

/* Importing all the required stuff, you should know this. */
const { Client, Intents } = require('discord.js');
const music = require('@koenie06/discord.js-music');
const events = music.event;

events.on('playSong', async (channel, songInfo, requester) => {

    /* See all the 'songInfo' options by logging it.. */

    channel.send({
        content: `Started playing the song [${songInfo.title}](${songInfo.url}) by \`${songInfo.author}\`.
        This was requested by ${requester.tag} (${requester.id})`
    });

});

events.on('addSong', async (channel, songInfo, requester) => {

    /* See all the 'songInfo' options by logging it.. */

    channel.send({
        content: `Added the song [${songInfo.title}](${songInfo.url}) by \`${songInfo.author}\` to the queue.
        Added by ${requester.tag} (${requester.id})`
    });

});

events.on('playList', async (channel, playlist, songInfo, requester) => {

    /* See all the 'songInfo' and 'playlist' options by logging it.. */

    channel.send({
        content: `Started playing the song [${songInfo.title}](${songInfo.url}) by \`${songInfo.author}\` of the playlist ${playlist.title}.
        This was requested by ${requester.tag} (${requester.id})`
    });

});

events.on('addList', async (channel, playlist, requester) => {

    /* See all the 'playlist' options by logging it.. */

    channel.send({
        content: `Added the playlist [${playlist.title}](${playlist.url}) with ${playlist.videos.length} amount of videos to the queue.
        Added by ${requester.tag} (${requester.id})`
    });

});

events.on('finish', async (channel) => {

    channel.send({
        content: 'Party has been ended!'
    });

});

/* Log your client in with your token. */
client.login('Client token from https://discord.com/developers/applications');

🔚 The End

Did you really scroll this far? Holy sh*t! Here a cookie for you, hope you have a nice day. :)

Koenie06

Package Sidebar

Install

npm i @koenie06/discord.js-music

Weekly Downloads

7

Version

1.3.0

License

ISC

Unpacked Size

48.8 kB

Total Files

5

Last publish

Collaborators

  • koenie06