voice-discord

0.0.7 • Public • Published

🎵 This is an NPM library which makes it easy to play songs in your Discord bot. 🤖

Installation

To install this library, run the following command: npm install voice-discord

Usage

To use this library, you need to create a new instance of the Player class. You can do this by passing your bot's client to the constructor:

Playing a song 🎶

const { Client, GatewayIntentBits } = require('discord.js');
const { Player } = require('voice-discord');

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

const player = new Player(client);

client.on('ready', async () => {
    console.log('Ready!');
    channel = client.channels.cache.get('channel id'); // or get channel some other way
    await player.connect(channel); // Connect to voice channel, fires a 'connected' event
});

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!play')) {
        const url = message.content.split(' ')[1]; // Get URL from message
        const song = await player.play(url); // Play song, fires a 'songStarted' event
        message.channel.send(`Now playing: ${song.name}`); // Send a message when song starts playing
    }
})

client.login('token');

Pausing, Resuming, and Stopping a song ⏸️ ▶️ ⏹️

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!pause')) {
        player.pause(); // Pause the current song, fires a 'songPaused' event
    }
    if (message.content.startsWith('!resume')) {
        player.resume(); // Resume the current song, fires a 'songResumed' event
    }
    if (message.content.startsWith('!stop')) {
        player.stop(); // Stop the current song, fires a 'songStopped' event
    }
})

Changing the volume 🔊

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!volume')) {
        const volume = parseInt(message.content.split(' ')[1]); // Get volume from message
        player.setVolume(volume); // Set volume, fires a 'volumeChanged' event
    }
})

Skipping a song ⏭️

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!skip')) {
        player.skip(); // Skip the current song, fires a 'songSkipped' event
    }
})

Getting the current song 🎵

client.on('messageCreate', async (message) => {
    if (message.content.startsWith('!current')) {
        const song = player.nowPlaying // Get the current song
    }
});

Credits 📜

This library is created by LordOfCosmos or absolutegod..

Support 💬

None lmfaooooo.

Readme

Keywords

none

Package Sidebar

Install

npm i voice-discord

Weekly Downloads

21

Version

0.0.7

License

ISC

Unpacked Size

14.7 kB

Total Files

9

Last publish

Collaborators

  • lordofcosmos