I’m new to Discord bots

Note

If you are a developer, the Development installation page may be more suitable for you.

If you want to deploy your bot instance, take a look at Containers, Direct installation or Kubernetes (experimental).

Downloading the code

Use git to download the source code:

git clone git@github.com:pumpkin-py/pumpkin-py.git pumpkin
cd pumpkin

To update the bot later, run

git pull

Environment file

The file called .env (that’s right, just these four characters, nothing more) holds information pumpkin.py needs in order to start.

When you clone your repository, this file does not exist, you have to copy the example file first:

cp default.env .env

You’ll get content like this:

DB_STRING=
TOKEN=

After each = you must add appropriate value. For TOKEN, see the section Bot token below. For DB_STRING, see the manual for installation that applies to your setup.

Bot token

Token is equivalent to yours username & password. Every Discord bot uses their token to identify themselves, so it’s important that you keep your bot’s token on private place.

Go to Discord Developers page, click New Application button and fill the form.

Go to the Bot tab on the left and convert your application to bot by clicking Add Bot. Then enable all Privileged Gateway Intents (Presence, Server Members, Message Content). There are warnings about 100 servers, but we don’t need to worry about it.

On the top of this page, there is a Token section and a Reset Token button. Copy the generated token and put it into your .env file (if you don’t have any, see the section Environment file above) after the TOKEN=.

Open your .env file and put the token in.

You can invite the bot to your server by going to the OAuth2/URL Generator page, selecting bot and applications.commands scopes and Administrator bot permission to generate a URL. Open it in new tab. You can invite the bot only to the servers where you have Administrator privileges.

Virtual environment

Note

This section does not apply to Docker users, as their Docker container itself is virtual environment separated from the rest of the system.

pumpkin.py is Python application. That means that it is not compiled and run from machine code, but it’s being interpreted by the Python language running on your computer.

pumpkin.py uses some libraries. Library is a piece of code made by another developer, specialized for doing certain tasks. Nearly every Linux machine contains Python as part of the system, and that means that you’ll have some Python libraries installed before you start doing anything with pumpkin.py.

To prevent clashes with those libraries, or to prevent clashes with another Python applications on your system, it is recommended to use virtual environment, which locks all the application dependencies (the libraries) inside of your project directory, keeping the rest of your system free.

venv setup

You may need to install the virtual environment package first:

sudo apt install python3-venv

Once available on your system, you can run

python3 -m venv .venv

to set up the virtual environment in current working directory.

This only has to be done once, then it is set up forever. If you install newer version of Python (e.g. from 3.9 to 3.10), you may need to remove the .venv/ directory and perform the setup again.

venv usage

The following step has to be performed every time you want to run the bot.

source .venv/bin/activate

Once activated, you can install packages as you want, they will be contained in this separate directory.

To exit the environment, run

deactivate

See installation manuals for details on what to do once you are in virtual environment.

A small tip

When working on the bot (debugging, development) it is easier if you speed up environment variable import. Open the activate script (the .venv/bin/activate file) and insert to the end of it:

set -o allexport
source ./.env
set +o allexport

This way the variables will be set whenever you enter the virtual environment with the source .venv/bin/activate command, and you won’t have to run the source .env manually.