Hosting a Discord bot on Ubuntu 16.04 LTS

This post is about me trying to host a Discord bot for me and my friends that can play music while using Discord. We’ve been using different ones for a while now but they all lag a ton so I decided to host one myself since I have a virtual server from DigitalOcean for a few more months.

Massive thanks to whoever made Red and lets people use their code for free.

I’ll be using this handy guide that the developer(s) made.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Requirements

First I installed the pre-requirements

$ sudo apt-get update
$ sudo apt-get install python3.5-dev python3-pip build-essential libssl-dev libffi-dev git ffmpeg libopus-dev unzip -y

After that I cloned the bot with

$ git clone -b develop --single-branch hhtps://github.com/Twentysix26/Red-DiscordBot.git

I tried running the bot with

$ python3 launcher.py

And selected 4. Install requirements and from there the option 1. Install basic + audio requirements, but got and error that my pip was out of date, so it updated it using

$ pip3 install -U pip // this gave the message to use the next command
$ pip install --upgrade pip

I ran the launcher again and installed the requirements successfully.

Bot account

I made a bot account on on Discords site and followed the guide the Red developer made.

So now that I got my token I think I can run the bot.

Running the bot

I simply ran the bot by selecting 1. Run Red /w autorestart in case of issues

The first time you run the bot it asks for the token you got from Discord developers-page, I inserted the token and everything started running smoothly.

After a few test (played a few songs, tried out some of the commands) I decided it was time to configure it.

red.png

Autorestarting

First of all I wanted the bot to be automatic so I don’t have to use ssh to start it or have a terminal window open every time I or someone else wanted to use it. Thankfully there’s a guide for this too!

$ sudo nano /etc/systemd/system/red.service

And inside I pasted the following script and modified the “username”-parts.

[Unit]
Description=Red-DiscordBot
After=multi-user.target
[Service]
WorkingDirectory=/home/username/Red-DiscordBot
User=username
Group=usergroup
ExecStart=/usr/bin/python3.5 /home/username/Red-DiscordBot/red.py --no-prompt
Type=idle
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target

After that I enabled the bot to launch on boot and started it.

$ sudo systemctl enable red.service
$ sudo systemctl start red.service

Everything was working, now for the final test

$ sudo reboot

In under a minute the bot was up and running!

Max length of songs and cache size

Although this was configured in Discord not on Ubuntu I thought I’d write about these too.

Modifying everything is made super simple. Just give your prefix (I chose §§ since the last bot we used had §) and the first part of the command you want to use and it’ll tell you what to type after it. In my case I used audioset since the a problem we’ve faced with bots before is that you can’t play long playlists or songs (talking over an hour or two).

§§audioset maxlength 36000
§§audioset cachemax 500

Now the bot should be able to play songs up to 10 hours long without any hassle. We did try it with a 4 hour one and it worked fine, so I’ll declare it working as intended.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 We’ve been using the bot for about a week now and it’s magnificent!

The few problems we’ve faced so far have been when trying out the limits of the bot. F.ex. for some reason we couldn’t get a certain Soundcloud playlists to work that wasn’t even that big (iirc 55 songs). The bot does usually give out an error message that you can simply Google and find answers/solutions most of the time. Restarting the bot has solved the couple tilts we’ve managed to cause without extra hassle.

But no random crashes, no lag issues and it has been up 24/7 (with some troubleshooting related reboots) for the past week.

I would highly recommend this project to anyone who has a couple hours of extra time on their hands, the outcome has been even better than what I expected.

And finally a massive thank you to the developer(s) of Red, the bot is amazing!

bunnybo.png

Advertisements

One thought on “Hosting a Discord bot on Ubuntu 16.04 LTS”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s