I am aware that there are many Discord Music bots out there. I choose to build one for both practice and the server I am part of. It was quite interesting to build the first version, and the to refactor the code for a public release. At the current time, the system can only pull music from YouTube at the moment, though this is set to change. This Bot makes a cache of the audio files, since the bot was originally meant to be hosted on a Personal Windows Machine, where we were starving for bandwidth. While this current version of the Bot isn't as robust as other offerings on the internet, its quite simple to use and setup. At least I think so.
This version is more of preparing stage version. There are two major versions currently on the road map. This version sees a revamped Permissions system. Simply add your admin ids to the pool in the settings.json
file and the bot will only allow admin functions to those users.
This version sees streamlined updates and quality of life changes, making it easier for you to change the max song length. There are a couple other under the hood improvements and improvements to presentations.
- Flesh out permissions system so that the user never has to touch code to add functions to different user roles.
After cloning or downloading the current master branch, simply run npm install
in the folder, and npm
will take care of the rest. However, this bot makes use of Discord.Js, and as a result needs a couple other steps to get running.
- Ensure the FFMPEG is available on your machine and can be accessed via the command line from anywhere, i.e FFMPEG is in your PATH.
- Ensure that the folders
audio
,database
,logs
have all been created. As the system doesn't do it for itself.
On Linux:
sudo apt-get install build-essential
On Windows:
- You need Visual Studio and Python 2.7.
The bot is setup in such a way that you don't have to touch any of the code. All the user settings are found in the settings.json
file. I have provided an example file called settings.example.js
make sure to modify it and convert it to settings.json
.
{
"discord": {
"bot_token": "YOUR_BOT_TOKEN",
"vChannel": {
"connectBy": "id OR name",
"name": "CHANNEL_NAME",
"id": "CHANNEL_ID"
}
},
"user_roles": ["admin", "public"],
"users": {
"admin": ["ADMIN_ID"],
"public": []
}
}
- Discord.bot_token is used to connect your code to the Discord Bot Account.
- Discord.vChannel is the object which contains the information relating to the voice channel.
- Discord.vChannel.connectBy is the method to connect to the channel, either using its
name
orid
. - Discord.vChannel.name is the name of the channel to connect to. Only used if
connectBy
is set toname
. - Discord.vChannel.id is the id of the channel to connect to. Only used if
connectBy
is set toid
. - User_roles are the current available roles for the bot.
admin
andpublic
are the only roles currently available. - Users.admin is an array of ids which will contain all the user ids for the users you wish to grant administration permissions to.
This is what I use to keep my bot running all the time.
- Create a new user and give it permissions for a folder on your install.
- I used
/var/bot/PlayMusic
for the location andplaymusic
as the user. - Give the
playuser
permissions for the/var/bot/PlayMusic
folder.
- As a user with
sudo
create the file/etc/systemd/system/playmusic.service
. The Service I used was custom taliored for a Ubunut 17.04 Server Install.
[Unit]
Description=PlayMusic
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/bot/PlayMusic
User=playmusic
Group=playmusic
ExecStart=/usr/local/bin/node /var/bot/PlayMusic/pm.js
Restart=always
SyslogIdentifier=PlayMusic
[Install]
WantedBy=multi-user.target
- Then run the following lines.
systemctl enable playmusic.service
systemctl start playmusic.service
systemctl enable playmusic.service
ensures the services runs on startup.systemctl starts playmusic.service
starts the process immediately.
- "/help" => Displays this help system.
- "/play [song_title]" OR "/play [artist] > [song_title]" OR "/play [YOUTUBE VIDEO LINK]" => Will locate the song in the song database and add it to the playlist. It will begin playing immediately if no song is queued. Otherwise it will queue itself. It will reply with "No Matching Song/Artist Found." if the song isn't in the database. If you select a youtube video to play, the system will download the audio, and once the download is completed it will queue the song and begin playing asap.
- "/playlist" => will return the currently playing queue. As well as a numerical listing of the songs currently in queue.
- "/whatplaying" => will return the song title and artist title for the song that is currently playing in voice channel.
- "/next" => skips the song.
- "/library" OR "/library pg [#]" => shows the first 10 entries in the database, which is sorted in alphabetical order. Or goes a specific page in library.
- "/pause" => Pauses the currently playing song.
- "/resume" => resumes the previously paused song.
- "/stop" => stops currently playing song and prevents the song from moving to the rest of the playlist.
- "/volume [int]" => Sets the volume of the current track, where int is a value between 0 and 100 inclusive.
Developed by Vishal Ramki. Released under the MIT License.