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

discord-music-bot

v2.3.0

Published

Simple music bot for Discord servers.

Downloads

39

Readme

A Node.JS Discord bot that takes song requests from videos on YouTube, queues them and plays the audio of said videos on a voice channel.

I made it totally ad-hoc for my personal server so it doesn't support multiple servers for a single instance or anything like that, but it can be customised very easily to make it work on any server you want.

Contributors

  • SavageCore - Implemented support for requesting YouTube playlists, setting the current song in the "Now Playing" status in Discord, and the !setavatar and !setusername commands. Thanks!

Available commands

  • !request <video/playlist/alias> - Adds a YouTube video or playlist to the queue. You can provide the full URL, just the video ID, full playlist URL or an alias.
  • !search - Searches for a video on YouTube and adds it to the queue. Requires a YouTube API key.
  • !stop - Stops the playback, the bot will not continue with the pending queue until !resume is issued.
  • !resume - Allows the bot to play videos from the queue again after !stop was issued.
  • !np - Displays the title of the video that is being played.
  • !setnp <on/off> - Selects whether the bot will announce the title of the video it's about to play or not.
  • !commands - Displays all available commands, pretty much like this.
  • !skip - Skips the video that is being currently played.
  • !queue - Displays the queue.
  • !clearqueue - Sets the queue to an empty state, discarding all pending requests.
  • !remove <request index or 'last'> - Removes a specific request from the queue. !remove last will delete the last request that was added.
  • !setalias : Maps any word of your choice (alias) to a video URL or ID, so you can !request the alias instead.
  • !deletealias - Removes an existing alias.
  • !aliases - Displays the stored aliases.
  • !setavatar <image url/alias> - Set avatar of bot.
  • !setusername <username/alias> - Set username of bot.

How to make it work?

Obviously, you must install Node.JS if you haven't already. Any version above 6.0.0 should do. It's highly recommended that you run the server on a Linux environment, because some dependencies will probably complain if you try to install them on Windows.

Then, install the bot itself. Just open up a console, type npm install discord-music-bot and you're done. It should be fairly quick and painless.

Next, register a new Discord application for your own instance of the bot. Keep track of the Client ID and your token.

It's time to make the bot join your server: replace your Client ID on this URL and navigate to it https://discordapp.com/oauth2/authorize?&client_id=YOUR_CLIENT_ID_HERE&scope=bot&permissions=0. Select the server you want the bot to join and click Authorize. This step requires that you have manage permissions on the server, otherwise it will not appear in the server list you'll be prompted with. Your bot should now appear as Offline in your server.

Finally, let's bring it to life! It's as simple as executing this script:

var bot = require("discord-music-bot");

var serverName = "Your server name here";
var textChannelName = "Your text channel name here (without #)";
var voiceChannelName = "Your voice channel name here";
var aliasesFile = "A file the bot will use to store your aliases";
var botToken = "Your bot token here";

bot.run(serverName, textChannelName, voiceChannelName, aliasesFile, botToken);

The aliases file parameter can be just a filename or a path to a file. If it does not exist, it will be generated. If you provide a filename, it will be generated in the same folder as the previous script. Any filename will do.

The bot will join the voice channel that you configured when it connects to the server, but obviously you can move it to other voice channels once it joins. The text channel is the one the bot will use to listen to commands and announce stuff. Keep in mind that all names are case-sensitive!

Save it with whatever name you want (for instance, "bot.js") and then execute it using Node.JS: node bot.js. Your bot should now be up and running in your server!

Obtaining a YouTube API key

In order to use the !search command, you must provide the bot with a YouTube API key of your own. The process is quite simple:

  1. Register a Google account in the unlikely case you don't have one.
  2. Create a new project in the YouTube API Dashboard
  3. On the top bar, you will find your active project next to the Google logo. Select the newly created project if it isn't already and then click Enable to allow the project to use the YouTube API.
  4. Click on "Create Credentials", select "YouTube Data API v3" on the first dialog, "Another UI" on the second and "Public data" on the third. Click the blue button and you will receive your key.
  5. Add the following line in your startup script:
    bot.setYoutubeKey("place your API key here");