Skip to content

PapLion/Discord_Exporter

Repository files navigation

Discord Exporter

A production-ready FastAPI application for exporting Discord channel messages to multiple formats (JSON, JSONL, TXT, CSV, HTML).

Features

  • 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)

Quick Start

Using Docker Compose

# 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/health

Environment Variables

Create 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 the Image

docker build -t discord-exporter:latest .

Run the Container

# 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

Docker Compose (Recommended)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f api

# Stop services
docker-compose down

API Endpoints

Health Checks

Endpoint Method Description
/api/v1/health GET Basic health check
/api/v1/health/live GET Liveness probe
/api/v1/health/ready GET Readiness probe

Export

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

System

Endpoint Method Description
/api/v1/info GET API information
/api/v1/metrics GET System metrics

Export Request Example

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"]
  }'

Response

{
  "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"
  ]
}

Export Formats

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

Development Setup

Prerequisites

  • Python 3.11+
  • Redis (optional, for async job processing)

Local Setup

# 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
pytest

Code Style

This project uses:

  • Black for code formatting
  • Flake8 for linting
  • MyPy for type checking
# Format code
black .

# Lint
flake8 .

# Type check
mypy .

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=app --cov-report=html

# Run specific test file
pytest tests/unit/test_export_service.py

License

MIT

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages