THE GUIDE TO THE EASY SERVERSIDE MUSICBOT
TABLE OF CONTENTS
- Introduction
- Prerequisites/specifications
- Installation
- Install packages needed
- Run everything
- FAQ
INTRODUCTION
NOTE FOR MOD: If this is posted in the wrong forum, feel free to move it. I'm new around these forums and this seemed like the place to post it. Cheers 
Hello there, curious reader. If you stumbled upon this thread, you are most likely looking for a guide on how to make your own, scriptable music bot with your own music and your own services. Please be aware that this guide ONLY covers Ubuntu and I will therefore not be taking ANY questions not related to that operating system. If you got this far, please be noted that while this is a tutorial, you also need a fairly good understanding of the syntax of linux systems in general as not every command will be explained throughout the tutorial.
If you would just like to get started, go down to requirements. If you don't mind me rambling, stay here for awhile. So, the reason I figured out how to do this was due to a couple of different reasons. First off, we needed a free music bot on our server, and secondly, I needed some kind of coding challenge. So while this might not be the most daunting adventure, be clear that you may have to google if missing dependencies or other bugs within Ubuntu (or another linux system, if you feel comfortable porting my commands from Ubuntu to, say, debian). With no further ado, let's get started.
PREREQUISITES/SPECIFICATIONS
To get this up and running, there are a couple of things that are absolutely needed and other things that are simply nice to have installed.
REQUIRED:
- screen - a useful tool to managing multiple instances of things. This or an alternative is a must, but I will assume that you have this installed. You should be able to install this by typing
Code:
sudo apt-get install screen
NICE TO HAVE:
- aptitude - this tool helps you locate a lot of the packages if you aren't sure of what they are named or if you are missing dependencies. This package can be installed by typing
Code:
sudo apt-get install aptitude
Apart from that, I am running my TeamSpeak3 server on a VPS with 3GB RAM and the client is also running on this, however that is way above what is needed. The minimum requirement is around 512mb RAM to make this setup work. You also need to have the port 6680 open and free and be a super user (i.e. being able to use sudo).
INSTALLATION
The quick way
First step is to install all the things that we need to get the different screen sessions up and running and speaking to each other. For those of you who just want to copy it in and have it work, here's almost all the commands needed:
Code:
sudo wget -q -O - http://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list http://apt.mopidy.com/mopidy.list
sudo apt-get update
sudo apt-get install screen xvfb libglib2.0-0 libpng12-0 libxcursor1 libxinerama1 \
libxrandr2 libfontconfig1 pulseaudio mopidy
wget https://raw.githubusercontent.com/DaBs/tsmusicbot/master/Xvfb
sudo mv Xvfb /etc/init.d
sudo chmod 755 /etc/init.d/Xvfb
sudo useradd -r debian-xvfb
sudo /etc/init.d/Xvfb start
sudo wget -q https://raw.githubusercontent.com/DaBs/tsmusicbot/master/mopidy.conf -O ~./configure/mopidy/mopidy.conf
sudo screen -d -m -S pulseaudio pulseaudio
sudo screen -d -m -S mopidy mopidy
sudo wget -q http://dl.4players.de/ts/releases/3.0.15/TeamSpeak3-Client-linux_amd64-3.0.15.run
sudo chmod u+x ./TeamSpeak3-Client-linux_amd64-3.0.15.run
./TeamSpeak3-Client-linux_amd64-3.0.15.run
From here, you will be asked a lot of things regarding the installation. Once this is finished, you should be ready to execute the rest of the commands:
Code:
sudo screen -S ts3_musicbot
And then, when inside this screen, run the following command. Depending on where you installed the TeamSpeak3 client, this may vary, but my command looks as follows:
Code:
DISPLAY=:99 /home/TeamSpeak3-Client-linux_amd64/ts3client_runscript.sh ts3server://yourserver.name.com?port=9987&nickname=MusicBot
Install Pulseaudio
First off, we need to install some pretty simple basics, also described in the above section. The most vital is pulseaudio, which is the virtual audio buffer that you are going to be using to channel whatever music is being played on your VPS out through the TeamSpeak3 client that we will call MusicBot later. So, to install that, do the following:
Code:
sudo apt-get install pulseaudio
After you've installed this, run the commands
Code:
screen -d -m -S pulseaudio pulseaudio
screen -ls
This should turn out a list of active screens, where pulseaudio should be one of them.
All good, now we have something that can play our music. Now we need something so we can control it. This means that we need to install mopidy. Mopidy is merely a music player, but since it has a lot of options for where to get the music from (e.g. Spotify, YouTube and others via plugins), this is what we will be using in this tutorial. This is fairly straightforward and on their side they have a tutorial for it, but I'll paraphrase it here just for the sake of consistency:
Install Mopidy
- Add the archive's GPG key: This is done by running the command
Code:
wget -q -O - http://apt.mopidy.com/mopidy.gpg | sudo apt-key add -
- Add sources to your sourcelist: Here you can run the command
Code:
sudo wget -q -O /etc/apt/sources.list.d/mopidy.list http://apt.mopidy.com/mopidy.list
- Install Mopidy and dependencies: Now we need to install it. Also pretty simple and done with two commands:
Code:
sudo apt-get update
sudo apt-get install mopidy
- Install extra plugins: Now let's say you want spotify support or something along those lines. To list all the different extensions you can run
Code:
apt-cache search mopidy
and thereafter install it with the usual
Code:
sudo apt-get install mopidy-<whatever the extension name>
- Configure Mopidy: This one is a little harder. If you want any help apart from the basics needed in this tutorial, please go to their site. What we want in the first place is merely to setup the basics, so type
Code:
sudo vim ~/.config/mopidy/mopidy.conf
. In there, you want to find the place where it says
[http]
enabled = false
hostname = 0.0.0.0
port = 6680
static_dir = /usr/www/mopidy
zeroconf = Mopidy HTTP server on $hostname
and change the enabled = false to enabled = true.
Once these steps are done, you can run Mopidy with a web interface, which means you can control it from your browser. To run mopidy, you simply type
Code:
screen -d -m -S mopidy mopidy
and then a to check if it started properly and if it did, well, hurray, everything works and you can now connect to your mopidy web interface on yourIPorDomain.com:6680! For those of you with issue in the port forwarding section, please attempt the command
Code:
sudo iptables -A INPUT -i eth0 --proto tcp --dport 6680 -j ACCEPT
Install Xvfb
Now most of you go like "Well, this is all good, but what now? I can play music, but nobody can hear two fucks, so what's the point?" Now, we need to get our TeamSpeak3 client running. This is also fairly simple, but requires a virtual display buffer too, as I presume your VPS does not have a screen attached. So go ahead and run the following pile of commands:
Code:
sudo apt-get install screen xvfb libglib2.0-0 libpng12-0 libxcursor1 libxinerama1 \
libxrandr2 libfontconfig1
wget https://raw.githubusercontent.com/DaBs/tsmusicbot/master/Xvfb
sudo mv Xvfb /etc/init.d
sudo chmod 755 /etc/init.d/Xvfb
sudo useradd -r debian-xvfb
sudo /etc/init.d/Xvfb start
That is an awful lot of commands and one of the includes downloading something, but I'll walk you through them. The first line simply installs the depencies we need, the second downloads the daemon for the virtual framebuffer, the third moves the daemon to the proper location, the fourth makes sure that it's executable, the fifth adds a new user solely responsible for xvfb and the sixth simply starts the virtual framebuffer (xvfb) with the file from earlier, which automatically specifies that it needs to start it as debian-xvfb. So all in all, all good!
Install TeamSpeak3 client
Now, we can get to actually making the teamspeak3 client work. First, we need to download the damn client, so go ahead and run
Code:
cd /home/
sudo wget -q http://dl.4players.de/ts/releases/3.0.15/TeamSpeak3-Client-linux_amd64-3.0.15.run
, or if there's a newer version, find the url yourself on the download site. Then, run
Code:
sudo chmod u+x ./TeamSpeak3-Client-linux_amd64-3.0.15.run
./TeamSpeak3-Client-linux_amd64-3.0.15.run
to install the client. This will ask you about the license primarily I believe. Once it's done, we need to start up the TeamSpeak3 client. Assuming that it installed into /home/, you can run the following command:
Code:
sudo screen -S ts3_musicbot
which starts up a separate screen for the client and then, when you are inside the screen, run the command:
Code:
DISPLAY=:99 /home/TeamSpeak3-Client-linux_amd64/ts3client_runscript.sh ts3server://yourserver.name.com?port=9987&nickname=MusicBot
This should result in a new fella on your server joining with (hopefully, this has yet to work for me properly) the name MusicBot and with a little blue icon in front of him. Things should be okay from here. Next up, you simply detach from the screen by pressing CTRL + A and then CTRL + D and now you are back to normal.
To add music, go check out Mopidy's small guide on where to find the local directory or simply use the Soundcloud, Spotify or one of the other extensions available by typing "sudo apt-get install mopidy-<whatever_you_wanna_install>" minus the <> brackets.