Discord Economy Bot
Virtual Currency, Leveling & Role Shop Bot
Project Overview
A professional Discord bot built with Python featuring a comprehensive economy system with virtual currency, XP/leveling mechanics, voice channel rewards, and a role shop system. The bot uses modern Discord slash commands and async database operations for optimal performance.
Key Features
1. Economy System
- Virtual Currency (Coins): Users earn and spend coins
- Balance Management: Check personal or other users' balances
- Admin Controls: Give/take coins with audit logging
- Leaderboard: Top 10 richest users display with medals
2. XP & Leveling System
- Experience Points: Earned alongside coins (1 XP = 1 coin)
- Level Calculation: Level = (XP // 100) + 1
- Level Up Notifications: Automatic alerts when users level up
- Progress Tracking: Users can view their XP progress
3. Reward Mechanisms
- Message Rewards: 1 coin per 10 messages (30-second cooldown)
- Voice Chat Rewards: 5 coins every 10 minutes in VC
- Anti-Spam Protection: Cooldown system prevents abuse
- AFK Detection: Skips rewards for deafened/AFK users
4. Role Shop System
- Purchasable Roles: 4 roles with different prices:
- VIP (250 coins) - 💎 Very Important Person
- Royal (500 coins) - 👑 Exclusive Royal status
- Elite (750 coins) - 🔥 Elite member status
- MVP (1000 coins) - 🏆 Most Valuable Player
- Interactive UI: Discord button-based purchase confirmation
- Role Duration: Configurable expiration (default: 30 days)
- Security: User-locked buttons, balance verification
5. User Statistics
- Profile Display: Avatar, level, XP, balance, join date
- Message Tracking: Total message count
- VC Time Tracking: Total voice chat minutes
- First Seen Timestamp: User registration tracking
6. Administrative Features
- Staff Logging: All admin actions logged to dedicated channel
- Error Handling: Global error handlers for slash/prefix commands
- Audit Trail: Coin modifications tracked and reported
- Bot Health: Ping command with latency indicator
7. Modern Discord Integration
- Slash Commands: Modern Discord command UI with discovery
- Permission Checks: Built-in role-based access control
- Interactive Components: Buttons for purchase confirmations
- Rich Embeds: Consistent, professional UI design
- Ephemeral Responses: Hidden responses for sensitive operations
Technology Stack
discord.py 2.3.0+
Python 3.x
SQLAlchemy 2.0+
aiosqlite 0.19.0+
SQLite
python-dotenv 1.0.0+
aiohttp 3.8.0+
Pillow 10.0.0+
Railway
Nixpacks
Architecture Highlights
Modular Cog-Based Design
- core.py: Basic commands (ping, userinfo, sync)
- economy.py: Economy operations (balance, give, take, top)
- shop.py: Shop system (shop, purchase UI)
- events.py: Event listeners and background tasks
Database Schema (Single Table Design)
- User ID, Guild ID, Username
- Balance, XP, Level
- Message Count, VC Minutes
- Timestamps (joined_at, last_message_at, last_reward_at)
Background Tasks
- VC Reward Loop: Runs every 10 minutes
- Message Cooldowns: In-memory tracking for anti-spam
Security Features
- Environment variable management (no hardcoded secrets)
- Role hierarchy validation
- Transaction-based database operations
- User-locked interactive components
Deployment
- Railway Cloud: Free hosting with persistent storage
- Automatic Deployments: Git push triggers rebuild
- Volume Storage: Persistent database across restarts
- Environment Variables: Secure configuration management