A modern Discord bot management system built with FastAPI + React architecture, supporting multiple bot management and AI agent functionality.
- 🤖 Multi-Bot Support - Create and manage multiple Discord bots
- 🧠 AI Agent Integration - Intelligent agent system based on Google ADK
- 🌐 Modern Web UI - React + TypeScript + Tailwind CSS management interface
- 🗄️ PostgreSQL Database - Persistent storage for bot configurations and data
- ⚡ Redis-based State Management - Real-time bot lifecycle management
- 🛠️ Rich Tool Ecosystem - Search, content extraction, math, notes, and more
- 🔄 Real-time State Monitoring - Live bot status monitoring and management
- 🧪 Comprehensive Testing Suite - End-to-end testing system
- 🔐 Secure Authentication - JWT-based authentication system
- 📊 Modern API - RESTful API design with OpenAPI documentation
- Python 3.14
- PostgreSQL 15+
- Redis 7+
- Node.js 20+ and pnpm
- uv (Python package manager)
- 本專案目前目標執行版本為 Python 3.14(
>=3.14,<3.15)。 - free-threaded(
--disable-gil)建置僅作為相容性驗證選項,並非正式生產預設。 - 另提供
3.15-dev與3.14t(free-threaded)非阻斷驗證軌,用於觀察相依套件支援狀態。 - 一次性升級指引(建議):
pyenv install 3.14.2
pyenv local 3.14.2
uv sync
uv run python -m pytest tests/runtime/test_python_runtime_guard.py -v可使用矩陣腳本一次執行穩定版與非阻斷驗證:
./scripts/runtime_matrix.shgit clone https://github.com/yourusername/discord-agents.git
cd discord-agents# Install dependencies using uv
uv sync
# Set up environment variables
cp .env.example .env
# Edit .env with required configurationscd frontend
pnpm install
cd ..# Run database migrations
python migrate.pyCreate a .env file in the root directory with the following required variables:
# Database
DATABASE_URL=postgresql://username:password@localhost:5432/discord_agents
# Redis
REDIS_URL=redis://localhost:6379/0
# API Keys
GOOGLE_API_KEY=your_google_api_key
TAVILY_API_KEY=your_tavily_api_key
# Security Settings
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# CORS Settings
CORS_ORIGINS=["http://localhost:5173","http://localhost:3000"]# Start both backend and frontend
python start.py
# Or start separately
python start_dev.py # Backend only
cd frontend && pnpm dev # Frontend only# Start with production configuration
python start_prod.py# Build image
docker build -t discord-agents .
# Run container
docker run -p 8080:8080 --env-file .env discord-agentsAfter startup, you can access the application at:
- Main Application: http://localhost:8080
- API Documentation: http://localhost:8080/api/docs
- Development Frontend: http://localhost:5173 (development mode only)
Backend:
- FastAPI (Web framework)
- SQLAlchemy (ORM)
- Alembic (Database migrations)
- Redis (State management)
- Google ADK (AI agents)
- Discord.py (Discord integration)
Frontend:
- React 19 + TypeScript
- Vite (Build tool)
- Tailwind CSS (Styling framework)
- Radix UI (UI components)
- TanStack Query (State management)
- React Hook Form (Form handling)
discord-agents/
├── discord_agents/ # Main application package
│ ├── fastapi_main.py # FastAPI application entry point
│ ├── api/ # API routes
│ │ ├── auth.py # Authentication API
│ │ ├── bots.py # Bot management API
│ │ ├── admin.py # Admin API
│ │ └── health.py # Health check API
│ ├── core/ # Core functionality
│ │ ├── config.py # Application configuration
│ │ ├── database.py # Database connections
│ │ ├── security.py # Security-related functions
│ │ └── migration.py # Auto migrations
│ ├── models/ # Database models
│ ├── schemas/ # Pydantic models
│ ├── services/ # Business logic services
│ ├── domain/ # Domain logic
│ │ ├── agent.py # AI agent definitions
│ │ ├── bot.py # Discord bot management
│ │ ├── tools.py # Tool registry
│ │ └── tool_def/ # Individual tool implementations
│ ├── scheduler/ # Bot scheduling and management
│ │ ├── worker.py # Bot manager
│ │ ├── broker.py # Redis state management
│ │ └── tasks.py # Background tasks
│ ├── cogs/ # Discord bot cogs
│ └── utils/ # Utility functions
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── lib/ # Utility functions
│ │ └── assets/ # Static assets
│ ├── package.json # Frontend dependencies
│ └── vite.config.ts # Vite configuration
├── tests/ # Test files
├── migrations/ # Database migration files
├── prompts/ # AI prompt templates
├── logs/ # Log files
└── data/ # Data files
The system includes the following built-in tools:
- Search Tool (
search) - Web search functionality - Life Environment Tool (
life_env) - Life simulation and advice - RPG Dice Tool (
rpg_dice) - Game dice functionality - Content Extractor Tool (
content_extractor) - Web content extraction and analysis - Summarizer Tool (
summarizer) - Text summarization - Math Tool (
math) - Mathematical calculations - Notes Tool (
notes) - Note-taking and management
# Run all tests
uv run python -m pytest tests/ -v
# Run specific tests
uv run python -m pytest tests/test_e2e.py -v # End-to-end tests
uv run python -m pytest tests/test_tools.py -v # Tool tests
# Run tests with coverage report
uv run python -m pytest tests/ --cov=discord_agents --cov-report=htmlEnsure PostgreSQL and Redis services are running:
# Start PostgreSQL (macOS example)
brew services start postgresql
# Start Redis (macOS example)
brew services start redis# Build image
docker build -t discord-agents .
# Run container
docker run -d \
--name discord-agents \
-p 8080:8080 \
--env-file .env \
discord-agentsCreate docker-compose.yml:
version: '3.8'
services:
app:
build: .
ports:
- "8080:8080"
environment:
- DATABASE_URL=postgresql://postgres:password@db:5432/discord_agents
- REDIS_URL=redis://redis:6379/0
depends_on:
- db
- redis
db:
image: postgres:15
environment:
- POSTGRES_DB=discord_agents
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
volumes:
- redis_data:/data
volumes:
postgres_data:
redis_data:- Create a new tool file in
discord_agents/domain/tool_def/ - Implement the tool following existing patterns
- Register the tool in
discord_agents/domain/tools.py - Add tests for the new tool
- API routes are defined in the
discord_agents/api/directory - Use Pydantic models for data validation
- Follow RESTful API design principles
cd frontend
pnpm dev # Start development server
pnpm build # Build for production
pnpm lint # Run code linting- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Bot won't start: Check token validity and permissions
- Redis connection errors: Verify Redis URL and connectivity
- Database errors: Check migration status and connection
- Tool loading failures: Verify tool registration in TOOLS_DICT
- Import errors: Check stub modules in test environment
# Check bot status
python -c "from discord_agents.scheduler.broker import BotRedisClient; print(BotRedisClient().get_all_bot_status())"
# Test database connection
python -c "from discord_agents.models.bot import BotModel; print(BotModel.query.count())"
# Verify tool loading
python -c "from discord_agents.domain.tools import Tools; print(Tools.get_tool_names())"