Skip to content

Instantly share code, notes, and snippets.

@Exenifix
Last active July 17, 2022 09:45
Show Gist options
  • Save Exenifix/a8aa68a4976389757ff3121e6daadcf6 to your computer and use it in GitHub Desktop.
Save Exenifix/a8aa68a4976389757ff3121e6daadcf6 to your computer and use it in GitHub Desktop.
How to setup Ubuntu 20.04 server for hosting python discord bots

Server Setup

1. Try running these commands to check if python has already been preinstalled:

$ python3
$ python
$ py
$ py3

If the python IDLE launched, skip to step 3

2. Run the following commands:

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt update

Now, when everything is ready for the python installation, you can install it

$ sudo apt install python3.8 #or any other python version eg python3.10

3. Install the pip:

$ sudo apt install python3-pip #if this didn't work try the one below
$ sudo apt install python-pip3

Now you can use it like

$ pip3 install discord.py

Running the Bot

Docker

Docker is containerization utility that is very powerful and is recommended for running applications like discord bots. Check out my tutorial about using it.

Screen

Screen is basically a background terminal you can attach to, detach and kill.

Installing screen

$ sudo apt install screen

Creating a new screen

$ screen -S nice-screen-name

Launch the application

We highly encourage to use venv for running the applications, although it is not really necessary

$ cd path/to/your/bot/dir
$ python3 -m venv venv
$ . venv/bin/activate 
$ python3 main.py  # or whatever your start script is named

Detaching from a screen

Ctrl + A, D

Reattaching to a detached screen

$ screen -r nice-screen-name

Listing all the active screens

$ screen -ls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment