DEV Community

BiasedKiwi
BiasedKiwi

Posted on

Chapter 1. Initial Setup

Have you ever been on Discord? If yes, then you've probably seen a Discord bot before, they appear as regular members in a server, except with a "BOT" tag next to their username. In Discord, a bot can be summoned by sending a command in chat.

Prerequisites

This tutorial expects you to have at least a decent understanding of Python. Rest assured, even if we will use async syntax, an understanding of asynchronous programming is not needed.

Preparing our dev environment.

First things first, we'll need to install a version of Python higher than 3.8. If you don't already have it installed, you can install it here.

Once you've installed Python, you can check if your python executable is working properly by making it print the Python version. On linux/macOS:

$ python3 --version
Enter fullscreen mode Exit fullscreen mode

Windows:

C:\> python --version
Enter fullscreen mode Exit fullscreen mode

If your Python executable is working properly, you should see this:

Python 3.8.10  # This number can be higher, but not lower.
Enter fullscreen mode Exit fullscreen mode

This step is optional, but highly recommended. We will create a
virtual environment using venv. In your Discord bot's root directory, execute this command:

python3 -m venv .venv  # Linux/macOS
Enter fullscreen mode Exit fullscreen mode

Windows:

C:\> python -m venv.venv
Enter fullscreen mode Exit fullscreen mode

We can activate our environment using source on Linux/macOS

$ source /.venv/bin/activate
Enter fullscreen mode Exit fullscreen mode

On Windows:

C:\> /.venv/Scripts/activate.bat
Enter fullscreen mode Exit fullscreen mode

Almost there! All we have to do now is to install Discord.py v2.0 using pip. Linux/macOS:

$ python3 -m pip3 install -U git+https://github.com/Rapptz/discord.py
Enter fullscreen mode Exit fullscreen mode

Windows:

C:\> python -m pip install -U git+https://github.com/Rapptz/discord.py
Enter fullscreen mode Exit fullscreen mode

Once that's done, you did it! We have successfully prepared our environment to start writing our Discord bot, see you in the next tutorial!

Further Reading

Top comments (0)