0.0.13 β€’ Published 12 months ago

voice-discord v0.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

🎡 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 🎢

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.title}`); // 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
    }
});

Properties πŸ“

Song Properties 🎡

  • title - The title of the song
  • id - The ID of the song
  • author - The author of the song
  • length - The length of the song in seconds
  • thumbnail - The URL of the song's thumbnail
  • desc - The description of the song
  • views - The number of views the song has
  • uploaded - The date the song was uploaded
  • genre - The genre of the song
  • keywords - The keywords of the song
  • url - The URL of the song

Playlist Properties πŸ“œ

  • title - The title of the playlist
  • songs - An array of Song objects

Player Properties πŸ€–

  • nowPlaying - The current song
  • volume - The current volume
  • queue - An array of Song objects

Options βš™οΈ

When creating a new instance of the Player class, you can pass an options object as the second argument. The following options are available:

  • leaveOnEnd - Whether or not to leave the voice channel when the queue ends. Defaults to false.
  • leaveOnEmpty - Whether or not to leave the voice channel when the voice channel is empty. Defaults to false.

Events πŸŽ‰

The following events are available:

  • connected - Fired when the bot connects to a voice channel.
  • disconnected - Fired when the bot disconnects from a voice channel.
  • songStarted - Fired when a song starts playing.
  • paused - Fired when a song is paused.
  • resumed - Fired when a song is resumed.
  • songStopped - Fired when a song is stopped.
  • songSkipped - Fired when a song is skipped.
  • songSkippedTo - Fired when a song is skipped to.
  • volumeChanged - Fired when the volume is changed.
  • queueEmpty - Fired when the queue ends.
  • error - Fired when an error occurs.
  • playlistStarted - Fired when a playlist starts playing.
  • playlistAdded - Fired when a playlist is added to the queue.

Credits πŸ“œ

This library is created by LordOfCosmos or absolutegod..

Support πŸ’¬

None lmfaooooo.

0.0.10

12 months ago

0.0.11

12 months ago

0.0.12

12 months ago

0.0.13

12 months ago

0.0.9

12 months ago

0.0.8

12 months ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago