Whether you’re an avid user of Discord, currently moderating a server, or own a server, you should definitely consider making a custom bot. This experience is both fun and practical as it can benefit your server and allow you a greater ability to customize as you see fit. While there are bots already available in the Discord ecosystem that are easy use, they might not meet your specific needs or they might be too feature-packed for the simple use case that you’re after so having the skills to create a custom bot are certainly an advantage.

This guide provides you with the initial steps for making your discord.py bot. If you’re interested in making one now or in the future, read below!

Prerequisites

Before we get started, you should be familiar with the following:

That’s about it. Don’t worry if **discord.py** is installed or not, I’ll handle that one for you too.


Getting Started

I am assuming you are in a new, empty directory, (preferably git initialized) to put all your code for this bot. If not, please do so now.

Installing the discord.py library

This should be a given — you’re making a discord bot with Python, right? Nonetheless,when installing discord.pyI recommend creating a Python virtual environment. Why does this matter? Well, if you are making this bot then you’re likely going to deploy it elsewhere (otherwise, the bot is only online when you’re running the Python bot script). In layman’s terms, a virtual environment keeps track of the Python packages that you use for the project so you can export them later. Most deployment methods depend on this export in the form of a .txt file and doing so saves you some hassle later on.

Heads Up: ## = comments (don't copy) ; $ = shell commands

## Go into your directory, if you haven't done so
$ cd <your_discord_bot_directory>
## Create your virtual environment (venv). I'm giving it the name
## `discordbot_env`, but you can change it to whatever you want.
$ python -m venv discordbot_env
## Activate the environment
$ source discordbot_env/bin/activate   ## (MacOS & Linux)
$ bot-env\Scripts\activate.bat         ## (Windows)
## Install discord.py
$ pip install -U discord.py

Now, fire up your favorite code editor or IDE, select your virtual environment as your Python environment and create a bot.py file in the working directory (the filename probably doesn’t matter).

#bots #programming #tutorial #discord #python

Discord.py: The  QuickStart Guide
1.30 GEEK