A Discord bot built with Python and clean architecture.
- Startup Greeting: Automatically says "👋 Hi everyone! I'm online and ready to go!" in the first available text channel of every server it's in when it starts.
- Message Tracking: Continuously tracks the last message sent by each user and automatically saves this data to a CSV file (
statistics/{Server Name}/last_messages.csv). - Commands (Prefix:
!):!export— Exports all statistics (members, last messages, and server structure) to thestatistics/{Server Name}/directory.!members— Exports a list of all server members, their roles, and account statistics (member join duration, account age, top role, and boost status) tostatistics/{Server Name}/members.csv.!serverinfoor!structure— Exports the complete server structure (channels, categories, and roles) tostatistics/{Server Name}/server_structure.md.!map— Rebuilds an Obsidian markdown tree of channels and role links inobsidian/{Server Name}/.
discord_bot/
├── main.py # Entry point
├── .env # Discord token (not committed)
├── .gitignore
├── requirements.txt
├── config/
│ ├── __init__.py
│ └── settings.py # Environment variable loading & validation
├── domain/
│ ├── __init__.py
│ └── models.py # Core business models (ChannelInfo, MemberInfo, etc.)
├── application/
│ ├── __init__.py
│ ├── command_handler.py # Routes messages to appropriate commands
│ ├── event_handlers.py # Startup event handlers
│ └── statistics_service.py # Gathers server data & exports reports
├── infrastructure/
│ ├── __init__.py
│ └── bot.py # Discord client setup & wiring
├── obsidian/ # Obsidian markdown map exports
└── statistics/ # Generated reports (CSV/Markdown)
└── {Server Name}/
├── last_messages.csv
├── members.csv
└── server_structure.md
-
Install dependencies:
pip install -r requirements.txt
-
Add your Discord bot token to the
.envfile:DISCORD_TOKEN=your_actual_token_here
-
Run the bot:
python main.py
| Layer | Responsibility |
|---|---|
| config | Load & validate environment variables |
| domain | Core business logic (entities, value objects) |
| application | Use cases, services, and event/command handlers |
| infrastructure | External services (Discord client, APIs…) |