A simple Discord.py bot (with cogs) template I use for all of my bots. Feel free to use and modify it.
-
Get a Bot Token:
Create a bot in Discord's Developer Portal and copy its token. Make sure you have enabled all of the Privileged Gateway Intents! -
Create Environment File:
Rename.env.exampleto.env. -
Add the Token:
Paste the token into the.envfile. It should look like this:# https://discord.com/developers/applications BOT_TOKEN="MTM0NTY3ODkwMTIzNDU2Nzg5.CDEfGH.IJKLMN_opq1234567890abcdef"
-
Install Dependencies:
Using pip:python -m pip install -r requirements.txt
Using uv:
uv sync
-
Create Your First Command (Cog):
The bot automatically detects (recursively) and loads cogs insidesrc/cogs/directory. Here is a simple "hello" slash command to get you started:import discord from discord import app_commands from discord.ext import commands from ..bot import Bot class Greetings(commands.Cog): def __init__(self, bot: Bot): self.bot = bot @app_commands.command(name="hello", description="Greets the user back.") async def hello(self, interaction: discord.Interaction): await interaction.response.send_message(f"Hello, {interaction.user.mention}!") async def setup(bot: Bot): await bot.add_cog(Greetings(bot))
For more information, please read this.
-
Run the Bot:
Using pip:python main.py
Using uv:
uv run python main.py