0.0.2 • Published 1 year ago

discord-melody v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

About

discord-melody is a simple music/voice package for discord.js that can play youtube urls (currently built to support v14 and v13)

Installation

ffmpeg is required or ffmpeg-static and to install this package do npm install discord-melody

Example

const { Client, GatewayIntentBits } = require('discord.js');
const prefix = "!";
const token = "YOUR-TOKEN";

const client = new Client({ intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.MessageContent
]});

client.once('ready', () => {
    console.log('online');
});

const { Player } = require('discord-melody');
const melody = new Player(client);

client.on('messageCreate', (message) => {
    if (!message.content.startsWith(prefix) || message.author.bot) return;

	const args = message.content.slice(prefix.length).trim().split(/ +/g);
	const command = args.shift().toLowerCase();

    if (command === 'ping') {
        message.reply('Pong!');
    };

    if (command === 'play') {
        const song = args.slice(0).toString().replaceAll(',', ' ');

        melody.join(message);
        melody.play(song);

        message.reply('Playing');
    };

    if (command === 'pause') {
        melody.pause();
        message.reply('Paused');
    };

    if (command === 'unpause') {
        melody.unpause();
        message.reply('Unpaused');
    };

    if (command === 'stop') {
        melody.stop();
        melody.disconnect();
        message.reply('Stopped')
    }
});

client.login(token);

Documentation

All music/playing related functions are made in the Player class

Player Class

/**
 * Constructor for class that requires a client argument
 * @param {string} client The client argument from making a new Client
*/

join()

/**
 * Joins a voice channel
 * @param {string} interaction The interaction argument provided by a user
*/

play()

/**
 * Plays an audio resource
 * @param {string} audio Audio url played off of youtube if it is a name then the package will grab the url itself
*/

pause()

/**
 * Pause current audio
*/

unpause()

/**
 * Unpauses current audio
*/

stop()

/**
 * Stops current audio
*/

disconnect()

/**
 * Disconnect from voice channel
*/