Discord Bot Development in Python

17-02-2021

Introduction

The goal of this project was to develop a Discord bot for my Discord server that would help automate tasks, provide users with essential information on command, and inject a touch of fun into the server. This bot was designed to save time by eliminating the need for repetitive messages, integrate embedded content for a better user experience, and provide interactive commands that would engage the community. Through this project, I deepened my understanding of Python development, API integrations, and deploying applications on both AWS and my home server.


Development Process

Setting Up the Environment

The first steps in the development process involved setting up my programming environment. I used Microsoft Visual Studio Code as my IDE, along with Python and necessary environment variables. Configuring the environment paths on Windows allowed the system to recognize Python, ensuring that the development process ran smoothly. Without this setup, the system might fail to locate Python, which can hinder progress.

Acquiring the Discord Bot Token

To interact with Discord's API, I needed to obtain a bot token from the Discord Developer Portal. This token serves as a form of authentication, allowing the bot to interact with the platform. I also had to choose the right scopes for the bot, which define its permissions. Careful selection of these permissions was critical; granting too many or too few permissions can cause issues with the bot’s functionality. I made sure to limit permissions to only what was necessary, avoiding the administrator scope to enhance security.

Discord Bot Permissions Scopes


Libraries and Coding

Required Libraries

To get the bot running, I installed libraries such as the Discord library, which allows developers to easily interact with the Discord platform. I used pip to install these packages, which provided the essential tools for managing commands, interactions, and message responses.

Writing the Bot Code

After the necessary libraries were installed, I started coding the bot. The initial version went through several iterations, with continuous testing and debugging. The bot was designed to automate various functions, such as sending messages, embedding content, and managing roles. After extensive testing, I finalized the code and ensured it was ready for deployment.

Bot Libraries Setup


Deployment

Initially, I deployed the bot on an AWS Ubuntu VM, allowing the bot to run continuously 24/7. This setup ensured reliable uptime and availability. However, I later migrated the bot to my Proxmox home server to centralize operations on my personal infrastructure.

The bot's source code has been published on GitHub, but it is kept private for now, as it is tailored to my personal server and for exclusive use within my community.


Bot Features and Commands

The bot’s functionality has proven beneficial in automating tasks such as message posting, role management, and integrating fun, interactive features for Discord members. It helps streamline communication, reduces administrative workload, and increases engagement by embedding certain roles into channels, making it easy for users to understand their responsibilities and access permissions.

Discord Bot Command Example


Conclusion

This project significantly improved my Python development skills and gave me hands-on experience with APIs and server deployment. The Discord bot has provided valuable automation features to my server, making it more interactive and efficient. By deploying it on both AWS and my home server, I gained insights into server management and application hosting.


Sources:

  1. Next.js
  2. Tailwind CSS
  3. Docker
  4. Portainer