A high-performance Discord bot system built in Rust that tracks cryptocurrency prices in real-time. Each cryptocurrency gets its own dedicated bot instance with live price updates, Discord status displays, and interactive slash commands.
- Real-time Price Tracking: Updates every 12 seconds from Pyth Network
- Multi-Bot Architecture: Dedicated bot instance per cryptocurrency
- Live Discord Integration: Dynamic nicknames and status messages
- Interactive Commands: Slash commands for instant price queries
- Historical Data: SQLite database with price history and trends
- Dynamic Nicknames: Shows current price (e.g., "BTC $67,234")
- Rotating Status: Cycles through percentage changes and cross-rates
- Trend Indicators: Visual arrows (ππ) for price movements
- Multi-Timeframe: 1h, 12h, 24h, 7d percentage changes
- Cross-Rate Conversion: BTC, ETH, SOL equivalent values
- Alpine Linux: Optimized containers (~115MB each)
- Health Monitoring: Built-in health check endpoints
- Auto-Recovery: Comprehensive error handling and retry logic
- Rate Limiting: Discord API protection with exponential backoff
- Data Persistence: SQLite with automatic cleanup
- Resource Efficient: ~3-6MB RAM per bot instance
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Pyth Network βββββΆβ Price Service βββββΆβ Shared Database β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β JSON Price Cacheβ β SQLite DB β
βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββ
β Discord Bots β
β βββββββ βββββββ βββββββ βββββββ βββββββ β
β β BTC β β ETH β β SOL β β ... β β ... β β
β βββββββ βββββββ βββββββ βββββββ βββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
- Price Service: Fetches and aggregates price data from Pyth Network
- Discord Bots: Individual bot instances for each cryptocurrency
- Shared Database: SQLite database for price history and calculations
- Health Monitoring: HTTP endpoints for service health checks
- Database Cleanup: Automated data retention management
- Docker and Docker Compose
- Discord Developer Account
- Basic knowledge of environment variables
git clone <repository-url>
cd crypto-discord-botcp .env.example .envEdit .env with your configuration:
# Update interval (seconds)
UPDATE_INTERVAL_SECONDS=12
# Discord Bot Tokens (create one bot per crypto)
DISCORD_TOKEN_BTC=your_btc_bot_token_here
DISCORD_TOKEN_ETH=your_eth_bot_token_here
DISCORD_TOKEN_SOL=your_sol_bot_token_here
# Add more tokens as needed...
# Optional: Pyth Network Feed IDs for direct API access
CRYPTO_FEEDS=BTC:feed_id_here,ETH:feed_id_here,SOL:feed_id_here# Build optimized containers
./build.sh
# Start all services
docker-compose up -d
# Verify deployment
docker-compose ps# Test health endpoints
curl http://localhost:9081/health | jq .
# View logs
docker-compose logs -f sol-botFor each cryptocurrency, you need a separate Discord bot:
- Go to Discord Developer Portal: https://discord.com/developers/applications
- Create New Application: Give it a name (e.g., "BTC Price Bot")
- Create Bot: Go to "Bot" section and create a bot
- Copy Token: Save the bot token securely
- Enable Intents: Enable "Server Members Intent" if needed
- Generate Invite: Create invite link with appropriate permissions
Your bots need these Discord permissions:
Change Nickname- To update price in nicknameUse Slash Commands- For interactive commandsSend Messages- For command responsesRead Message History- For command context
https://discord.com/api/oauth2/authorize?client_id=YOUR_BOT_ID&permissions=67584&scope=bot%20applications.commands
The system currently supports these cryptocurrencies:
| Symbol | Name | Status |
|---|---|---|
| BTC | Bitcoin | β Active |
| ETH | Ethereum | β Active |
| SOL | Solana | β Active |
| AVAX | Avalanche | β Active |
| BNB | Binance Coin | β Active |
| DOGE | Dogecoin | β Active |
| SUI | Sui | β Active |
| SEI | Sei | β Active |
| JLP | Jupiter LP | β Active |
| PUMP | Pump.fun | β Active |
| MSTR | MicroStrategy | β Active |
| HOOD | Robinhood | β Active |
| SBET | SportsBet | β Active |
| GOLD | Gold | β Active |
| SILVER | Silver | β Active |
Follow the Discord Bot Setup section to create a new bot for your cryptocurrency.
Add the new bot token to your .env file:
DISCORD_TOKEN_NEWCOIN=your_new_bot_token_hereAdd a new service to docker-compose.yml:
newcoin-bot:
build: .
volumes:
- ./shared:/app/shared
environment:
- DISCORD_TOKEN=${DISCORD_TOKEN_NEWCOIN}
- CRYPTO_NAME=NEWCOIN
- UPDATE_INTERVAL_SECONDS=${UPDATE_INTERVAL_SECONDS:-12}
command: ["./discord-bot"]
depends_on:
- price-service
restart: unless-stopped
ports:
- "9098:8080" # Use next available port
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3- Visit https://pyth.network/price-feeds
- Search for your cryptocurrency
- Copy the feed ID (hexadecimal string)
- Add to
CRYPTO_FEEDSin your environment
# Rebuild and restart
docker-compose down
docker-compose up -d --build| Command | Description | Example |
|---|---|---|
/price [crypto] |
Get current price info | /price BTC |
π BTC: $67,234.56 π +2.15% (1h) | π +5.23% (12h) | π -1.45% (24h)
π± Cross-rates: 1.000 BTC | 18.45 ETH | 705.2 SOL
Each bot cycles through these status messages:
- 1-hour change: "π +2.15% (1h)"
- BTC equivalent: "β 0.0234 BTC"
- ETH equivalent: "β 1.456 ETH"
- SOL equivalent: "β 234.5 SOL"
| Variable | Description | Default | Required |
|---|---|---|---|
UPDATE_INTERVAL_SECONDS |
Price update frequency | 12 |
No |
DISCORD_TOKEN_* |
Discord bot tokens | - | Yes |
CRYPTO_FEEDS |
Pyth Network feed IDs | - | No |
CRYPTO_NAME |
Cryptocurrency symbol | - | Yes |
CLEANUP_INTERVAL_HOURS |
Database cleanup frequency | 24 |
No |
Choose based on your needs:
- 12 seconds: Real-time updates (default)
- 30 seconds: Balanced performance
- 60 seconds: Lower resource usage
- 300 seconds: Minimal resource usage
Each service exposes a health endpoint:
- Price Service: No external port
- SOL Bot:
http://localhost:9081/health - BTC Bot:
http://localhost:9082/health - ETH Bot:
http://localhost:9083/health - (Additional bots on ports 9084-9096)
# Check all services
docker-compose ps
# Test specific health endpoint
curl http://localhost:9081/health | jq .
# Monitor resource usage
docker stats --no-stream# View all logs
docker-compose logs -f
# View specific service
docker-compose logs -f btc-bot
# View recent logs only
docker-compose logs --tail=50 price-service# Query database directly
docker-compose exec price-service ./db-query
# Manual cleanup
docker-compose exec db-cleanup ./db-cleanup
# Backup database
cp shared/prices.db backup/prices-$(date +%Y%m%d).db# Install Rust (if not already installed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Build project
cargo build --release
# Run price service locally
cargo run --bin price-service
# Run specific bot locally
CRYPTO_NAME=BTC DISCORD_TOKEN=your_token cargo run --bin discord-bot# Run tests
cargo test
# Check code formatting
cargo fmt --check
# Run linter
cargo clippy# Build all containers
./build.sh
# Build specific service
docker-compose build btc-bot
# Check image sizes
docker images | grep rustymcpricefaceBot not responding to commands:
- Verify bot token is correct
- Check bot permissions in Discord server
- Ensure slash commands are registered
- Check bot logs:
docker-compose logs bot-name
No price updates:
- Check price-service logs:
docker-compose logs price-service - Verify network connectivity
- Check Pyth Network status
- Ensure shared directory permissions are correct
Database errors:
- Check disk space:
df -h - Verify shared directory permissions:
ls -la shared/ - Check database file:
file shared/prices.db - Review database logs:
docker-compose logs db-cleanup
High resource usage:
- Monitor with:
docker stats - Check update interval settings
- Review log levels
- Consider increasing update intervals
# Access container shell
docker-compose exec btc-bot /bin/sh
# Check container health
docker-compose exec btc-bot curl localhost:8080/health
# View database schema
docker-compose exec price-service sqlite3 shared/prices.db ".schema"
# Check file permissions
docker-compose exec price-service ls -la shared/
# Test network connectivity
docker-compose exec price-service ping pyth.network# Reduce update frequency
UPDATE_INTERVAL_SECONDS=30
# Lower log levels
RUST_LOG=warn
# Optimize database
docker-compose exec price-service sqlite3 shared/prices.db "VACUUM;"This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Issues: Create an issue on GitHub
- Documentation: Check this README and inline code comments
- Logs: Always include relevant logs when reporting issues
- Health Checks: Use health endpoints to diagnose problems
Built with β€οΈ in Rust | Optimized for Alpine Linux | Production Ready π