npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

voice-discord

v0.0.13

Published

An NPM library which makes it easy to play audio in Discord!

Downloads

22

Readme

🎵 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.