Discord is a top-rated online chatting program, especially amongst the gaming community. A popular feature with these channels is the inclusions of bots that range from moderation commands, music bots, trivia bots, leveling, and much more. Most bots are run on servers, and you can invite, however many of these Bots require monetary requirements to unlock more features, which can be unstable and a security risk.
So, a growing trend lately is the rise of open-source, self-hosted free Discord bots, one of the absolute powerhouses in this field is called Red Discord Bot. Redbot comes with all features that can be enabled or disabled, along with a vast 3rdParty plugin page of community projects.
The Discord bot can be installed on various operating systems. However, you will learn how to install Redbot on a Ubuntu 20.04 LTS server for the tutorial, a popular choice amongst Discord bots.
Table of Contents
- 1 Prerequisites
- 2 Install GIT:CORE PPA
- 3 Install Dependencies – Python3, PIP, OpenJDK
- 4 Create a Virtual Environment
- 5 Install Redbot Discord Bot
- 6 Redbot Discord Bot Set-Up
- 7 Create Discord Bot Application
- 8 Enabling Privileged Intents
- 9 Comments and Conclusion
- Recommended OS: Ubuntu 20.04 – optional (Ubuntu 21.04)
- User account: A user account with sudo or root access.
- Required Packages: wget
Update Operating System
Update your Ubuntu 20.04 operating system to make sure all existing packages are up to date:
sudo apt update && sudo apt upgrade
Next, the prerequisites are:
- Python 3.8.1 or greater; Python 3.9 is currently not supported!
- Pip 18.1 or greater
- Git 2.11+
- Java Runtime Environment 11 (for audio support)
Install GIT:CORE PPA
You will need to install GIT:CORE PPA, which the git developers maintain. Our guide on how to install the custom PPA can be found here.
sudo apt install software-properties-common && sudo add-apt-repository ppa:git-core/ppa -y
Install Dependencies – Python3, PIP, OpenJDK
To install Python 3 and Pip3 and additional packages, Redbot requires running the following commands.
sudo apt install python3.8 python3.8-dev python3.8-venv python3-pip git openjdk-11-jre-headless build-essential nano -y
Create a Virtual Environment
Redbot is required to be installed in a virtual environment. You cannot skip this step.
You can create a virtual environment using the python-venv environment, which is the easier way as follows.
python3.8 -m venv ~/redenv
Then activate the virtual environment.
Next, you will be in the virtual environment shell, and you will notice your prefix will have (redenv) as this was the name you assigned when creating the environment.
(redenv) [email protected]:~$
Install Redbot Discord Bot
Now that you are in your virtual environment, you can install Redbot in the virtual environment you have created and run.
The first option, install without additional config backend support:
python3 -m pip install -U pip setuptools wheel && python3 -m pip install -U Red-DiscordBot -y
The second option, to install with PostgreSQL support:
python3 -m pip install -U pip setuptools wheel && python3 -m pip install -U "Red-DiscordBot[postgres]" -y
Redbot Discord Bot Set-Up
Now you have installed Redbot in your virtual environment. We can now set the discord bot up on your server.
To set up the Discord bot instance, type the following command.
This will set the location of data, your storage backend, and the instance’s name (used for running the bot).
Once done setting up the instance, run the following command to run Red:
Next, you will see the following output. The self prompts are pretty straightforward as per the below example.
First, you will see you enter the instance name. In our example, we used Redbot.
~$ redbot-setup Hello! Before we begin, we need to gather some initial information for the new instance. Please enter a name for your instance, it will be used to run your bot from here on out. This name is case-sensitive and should only include characters A-z, numbers, underscores (_) and periods (.). redbot
Depending on the install option you choose for back-end support, pick the storage backend.
We've attempted to figure out a sane default data location which is printed below. If you don't want to change this default please press [ENTER], otherwise input your desired data location. Default: /home/bytesboss/.local/share/Red-DiscordBot/data/redbot You have chosen /home/bytesboss/.local/share/Red-DiscordBot/data/redbot to be your data directory. Please confirm [Y/n]: y Please choose your storage backend (if you're unsure, just choose 1). JSON (file storage, requires no database). PostgreSQL (Requires a database server) 1
Once Redbot has finished setting up, your final output should be as follows.
Your basic configuration has been saved. Please run
redbot <name>to continue your setup process and to run the bot. First time? Read the quickstart guide: https://docs.discord.red/en/stable/getting_started.html
Create Discord Bot Application
Now, everything has been sorted with Redbot and your self-hosted server; when running the command “redbot <your instance name,” you would have noticed that you saw the following output.
Please enter a valid token. You can find out how to obtain a token with this guide: https://docs.discord.red/en/stable/bot_application_guide.html#creating-a-bot-account
You will need to create a Discord Bot application to enter a token ID. You achieve this in the following steps below.
Make sure you have created the discord account that will be its owner as below steps.
- Make sure you’re logged on to the Discord website.
- Navigate to the application page
- Click on the “New Application” button.
After clicking “New Application,” give your new Discord application a name and hit create.
Navigate to the “Bot” tab on the left-hand side of your developer Discord page, then hit add a bot.
Suppose you want others to be able to invite your bot to tick the Public Bot. Keeping it unticked will prevent others from asking your bot to their servers, and only you will be able to add the bot to servers (provided that you have needed permissions in the server you want to add the bot to).
Now, hit the copy the token button. You can now enter this in your Ubuntu terminal for the token ID. Do not share this token. It is a password and should be treated with the utmost care, or else security issues could occur.
Enabling Privileged Intents
Discord API requires all intents, or your Redbot instance will give you the following error output.
Red requires all Privileged Intents to be enabled. You can find out how to enable Privileged Intents with this guide: https://docs.discord.red/en/stable/bot_application_guide.html#enabling-privileged-intents
To enable the required privileged intents permissions, navigate to the Bot section in your Discord developers page.
Scroll down to the “Privileged Gateway Intents” section, enable both privileged intents and save your changes.
Next, re-run your Redbot instance. You now should see the error is gone and a new set-up option visible.
Choose a prefix for your Redbot to listen for in the Discord channels. Popular ones are! And @.
Pick a prefix. A prefix is what you type before a command. Example: !help ^ The exclamation mark is the prefix in this case. The prefix can be multiple characters. You will be able to change it later and add more of them. Choose your prefix: Prefix> !
Redbot instance is now running as per below.
Comments and Conclusion
Redbot is the most giant free, open-source, actively developed self-hosted discord bot known. If privacy concerns public discord bots, you can efficiently run this even for your friends in a VMware or Docker setup with self-hosting. The plugin libraries are vast and cover most of what popular Discord bots cover. However, if you want web UI’s, you will need a domain and some know-how—the trade-offs for running your Discord bot instance far outway any negatives. Also, Redbot is secure, giving you peace of mind.
Community plugins for Redbot which have been verified can be found by clicking here.