How to install a Discord bot based on Python?
It is recommended to perform the instructions below on a clean server, right after (re)installation. Click Reinstallation in the panel to do this.
Introduction
We assume the bot consists of 2 files:
- bot.py
- requirements.txt
The files have been uploaded to the default folder (folder /root)
Installing Python
Install Python along with venv:
apt update && apt install python3 python3-venv -y
Create Python virtual environment
Create directory:
mkdir ~/.venvs
Create virtual environment:
python3 -m venv ~/.venvs/discord
Activate virtual environment:
source ~/.venvs/discord/bin/activate
Install dependencies
Check the requirements.txt file. There should be a list of dependencies,
example of a correct one:
mysql-connector-python
nextcord
asyncio
datetime
Often an incorrect list is encountered in the form:
pip install mysql.connector
pip install mysql.connector
pip install nextcord
pip install asyncio
pip install datetime
pip install nextcord
pip install nextcord.ext
pip install nextcord.ui
pip install json
In this case, the pip install prefixes should be removed.
Instead of mysql.connector it should be mysql-connector-python.
json should be removed, and the .ext and .ui extensions should be removed from the nextcord package.
Proceed with the installation of dependencies:
pip install -r requirements.txt
If any errors occurred here, they should be carefully read and the problem solved.
Run the bot
python3 bot.py
If an error like ModuleNotFoundError: No module named 'flask' appeared,
it means a dependency is missing, in this case flask. This can be
easily fixed by installing this dependency:
pip install flask