My personal, modern, and type-safe Discord bot template written in Python with Pycord.
- uv for fast dependency management
- mypy for static type checking
- ruff for linting and formatting
- Main & debug bot configuration with
.envsupport
- Python 3.14 or higher
- uv package manager
-
Install dependencies:
uv sync
-
Configure environment variables:
- Copy
.env.exampleto.env - Get your bot token from the Discord Developer Portal
- Edit
.envand add your Discord bot token:token=YOUR_BOT_TOKEN_HERE uid=YOUR_BOT_ID_HERE
- Copy
-
Run the bot:
uv run python main.py
Pycord-Template/
βββ cogs/ # Bot command modules (cogs)
β βββ template.py # Example cog
βββ main.py # Bot entry point
βββ settings.py # Configuration management
βββ pyproject.toml # Project metadata and dependencies
βββ .env # Environment variables (create from .env.example)
βββ .env.example # Example environment variables
Create a new file in the cogs/ directory:
"""Your cog description."""
import discord
from discord.ext import commands
class YourCog(commands.Cog):
"""Your cog class description."""
def __init__(self, bot: discord.Bot) -> None:
"""Initialize the cog."""
self.bot = bot
@discord.slash_command(
name="your_command",
description="Your command description",
)
async def your_command(self, ctx: discord.ApplicationContext) -> None:
"""Your command implementation."""
await ctx.respond("Hello!")
def setup(bot: discord.Bot) -> None:
"""Set up the cog."""
bot.add_cog(YourCog(bot))Cogs are automatically loaded from the cogs/ directory when the bot starts.
For running a test bot alongside your main bot, you can add debug variables to your .env file.
The bot will use token_debug and uid_debug if they exist, otherwise it falls back to token and uid. Simply comment out or remove the debug variables to switch back to your production bot.