This repository contains a tutorial Python Discord bot used to teach contributors how to build and run a Discord bot using discord.py.
Project Goals:
- Provide a minimal, well-documented starter bot.
- Teach how to create a Discord Application and Bot in the Discord Developer Portal.
- Show contributors how to run and extend the bot locally.
What's Included
bot.py: Minimal bot implementation with apingcommand and basic event handlers.requirements.txt: Python dependency list..env.example: Example environment file showingDISCORD_TOKENusage..gitignore: Recommended ignores for Python projects.
Prerequisites
- Python 3.10+ installed.
- A Discord account and a server where you can add the bot for testing.
Quick start (local)
- Create a virtual environment and activate it:
python -m venv .venv
source .venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile based on.env.exampleand fill in your bot token:
DISCORD_TOKEN=your-bot-token-here
- Run the bot:
python bot.pyThe bot will print a logged-in message when ready.
Discord Developer Portal — Create a Bot (step-by-step)
-
Open the Discord Developer Portal: https://discord.com/developers/applications
-
Click New Application, give it a name, and create the application.
-
In the sidebar, go to Bot and click Add Bot → Yes, do it!
-
Under the Bot section:
- Copy the TOKEN (click
Reset Tokenif none exists) — this is the value forDISCORD_TOKENin your.envfile. - (Optional) Upload an avatar and edit the bot username.
- Under Privileged Gateway Intents, enable Message Content Intent if you want the bot to read message content (required for some bot features). Also enable Presence Intent or Server Members Intent if you plan to use those features.
- Copy the TOKEN (click
-
Invite the bot to your server:
- In the Developer Portal, go to OAuth2 → URL Generator.
- Under Scopes, check
botandapplications.commands(if you intend to add slash commands later). - Under Bot Permissions, select the permissions your bot needs (for the tutorial,
Send MessagesandRead Message Historyare sufficient). For admin testing you can temporarily selectAdministrator. - Copy the generated URL, open it in your browser, choose the server to add the bot to, and authorize it.
Example manual OAuth2 invite URL (replace CLIENT_ID and adjust permissions):
https://discord.com/oauth2/authorize?client_id=CLIENT_ID&permissions=8&scope=bot%20applications.commands
Bot usage
- Start the bot with
python bot.py. - In Discord, use
!pingto check the bot is responsive.
Environment variables
DISCORD_TOKEN— The bot token from the Developer Portal. Keep this secret.
Contributing
- Fork the repository and open a pull request with your changes.
- Suggested tasks for contributors:
- Add a cog demonstrating a useful feature (e.g., moderation, fun commands).
- Add unit tests or integration tests for command parsing/helpers.
- Add a CI workflow to run linting and tests on PRs.
Resources
- discord.py docs: https://docs.python.org/3/ and https://docs.discordpy.dev/en/stable/
If you want, I can also scaffold a cogs/ package, add a simple CI github/actions workflow, or add examples for slash commands. Which would you like next?