This is a simple Discord bot written in Python that utilizes the discord.py library to handle slash commands. It includes the pre-defined /ping command which responds with "Pong!" when called.
To run this bot, you'll need:
- Python 3.8 or higher
discord.pylibrary- A
.envfile with your bot token
git clone https://github.com/PedroDevJS/python-discord-template.git
cd python-discord-templateIf you don't have virtualenv installed, install it first:
pip install virtualenvThen, create and activate a virtual environment:
# For Windows
python -m venv venv
venv\Scripts\activate
# For MacOS/Linux
python3 -m venv venv
source venv/bin/activateOnce your virtual environment is activated, install the required packages using pip:
pip install -r requirements.txtCreate a .env file in the root directory of the project and add the following:
DISCORD_TOKEN=your_discord_bot_token_hereReplace your_discord_bot_token_here with your actual Discord bot token.
To run the bot, execute the following command:
python main.pyYour bot should now be online and connected to your Discord server.
Once the bot is running, it will respond to the following slash command:
This simple command responds with "Pong!" when invoked.
/ping→ Bot responds with "Pong!"
- Description: This command returns a simple "Pong!" response.
- Usage:
/ping- The bot replies with
Pong!
- The bot replies with
This file is the entry point of the bot. It loads and runs the bot, syncing the commands for the specified guild.
This file contains the PingCommand class, which defines the /ping command. It registers the command to respond with "Pong!" when invoked.
This file holds your environment variables, including your Discord bot token (DISCORD_TOKEN).
This file contains the necessary Python libraries that your project depends on. It should contain at least:
discord.py
python-dotenvYou can install these dependencies with pip by running the command mentioned in the Installation section.
This project is licensed under the GNU General Public License v3.0. You can freely use, modify, and distribute this code, but please ensure that any modifications or redistributions are done under the same license.
For more information about this license, please refer to the GNU General Public License v3.0.
- Replace
your_discord_bot_token_herewith your actual bot token in the.envfile. - Ensure that your bot is added to a server and has permissions to send messages.