A production-ready FastAPI application for exporting Discord channel messages to multiple formats (JSON, JSONL, TXT, CSV, HTML).
- Export Discord channel messages to multiple formats
- Async job processing with progress tracking
- Rate limiting and retry logic
- Docker deployment ready
- Health checks and metrics endpoints
- Background job queue (in-memory or Redis)
# Clone the repository
git clone <repository-url>
cd Discord_Exporter
# Start the services
docker-compose up -d
# Check health
curl http://localhost:8000/api/v1/healthCreate a .env file based on .env.example:
| Variable | Description | Default |
|---|---|---|
DEBUG |
Enable debug mode | false |
SECRET_KEY |
Secret key for sessions | change-me-in-production |
API_PREFIX |
API URL prefix | /api/v1 |
VERSION |
API version | 1.0.0 |
BACKEND_CORS_ORIGINS |
CORS origins (comma-separated) | (production: none) |
EXPORT_DIR |
Directory for exports | exports |
MAX_EXPORT_SIZE_MB |
Max export size in MB | 100 |
RATE_LIMIT |
API rate limit | 50/minute |
REDIS_URL |
Redis connection URL | redis://localhost:6379/0 |
LOG_LEVEL |
Logging level | INFO |
ASYNC_EXPORT_ENABLED |
Enable async export jobs | false |
docker build -t discord-exporter:latest .# Basic run
docker run -d \
-p 8000:8000 \
-v ./exports:/app/exports \
-e SECRET_KEY=your-secret-key \
discord-exporter:latest
# With Redis
docker run -d \
-p 8000:8000 \
-v ./exports:/app/exports \
-e SECRET_KEY=your-secret-key \
-e REDIS_URL=redis://host:6379/0 \
discord-exporter:latest# Start all services
docker-compose up -d
# View logs
docker-compose logs -f api
# Stop services
docker-compose down| Endpoint | Method | Description |
|---|---|---|
/api/v1/health |
GET | Basic health check |
/api/v1/health/live |
GET | Liveness probe |
/api/v1/health/ready |
GET | Readiness probe |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/export |
POST | Export channel messages |
/api/v1/jobs/{job_id} |
GET | Get job status |
/api/v1/jobs/{job_id} |
DELETE | Cancel a job |
/api/v1/channel/{channel_id} |
GET | Get channel info |
/api/v1/exports |
GET | List exported files |
/api/v1/exports/{filename} |
GET | Download export file |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/info |
GET | API information |
/api/v1/metrics |
GET | System metrics |
curl -X POST http://localhost:8000/api/v1/export \
-H "Content-Type: application/json" \
-d '{
"token": "your-discord-bot-token",
"channel_id": "123456789",
"output_dir": "exports",
"limit": 1000,
"export_formats": ["json", "jsonl", "txt", "csv", "html"]
}'{
"status": "success",
"message": "Successfully exported 1000 messages",
"message_count": 1000,
"exported_files": [
"exports/discord_export_channel_20240315_143022.json",
"exports/discord_export_channel_20240315_143022.jsonl"
]
}The exporter supports the following formats:
| Format | Extension | Description |
|---|---|---|
| JSON | .json |
Raw JSON array |
| JSONL | .jsonl |
One JSON object per line |
| TXT | .txt |
Human-readable plain text |
| CSV | .csv |
Comma-separated values |
| HTML | .html |
Styled HTML page |
- Python 3.11+
- Redis (optional, for async job processing)
# Clone the repository
git clone <repository-url>
cd Discord_Exporter
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
cd api
pip install -r requirements.txt
# Run the API
uvicorn app.main:app --reload
# Run tests
pytestThis project uses:
- Black for code formatting
- Flake8 for linting
- MyPy for type checking
# Format code
black .
# Lint
flake8 .
# Type check
mypy .# Run all tests
pytest
# Run with coverage
pytest --cov=app --cov-report=html
# Run specific test file
pytest tests/unit/test_export_service.pyMIT