Getting Started
This guide will help you set up and run the Smutje Discord bot locally for development or production.
Prerequisites
Before you begin, ensure you have:
- Rust (2024 edition) - Install via rustup
- Discord Bot Token - Create a bot at Discord Developer Portal
- Heimdall API - Running instance with GraphQL, REST, and WebSocket endpoints
- System API Key - Generated from Heimdall for bot authentication
Discord Bot Setup
-
Go to Discord Developer Portal
-
Click "New Application" and give it a name
-
Go to "Bot" section and click "Add Bot"
-
Copy the Bot Token (keep this secret!)
-
Enable these Privileged Gateway Intents:
PRESENCE INTENT(optional, for rich presence)SERVER MEMBERS INTENT(required for member sync)MESSAGE CONTENT INTENT(required for prefix commands)
-
Go to "OAuth2" > "URL Generator":
- Select scopes:
bot,applications.commands - Select bot permissions:
Administrator(or specific permissions) - Use the generated URL to invite the bot to your server
- Select scopes:
Environment Variables
Create a .env file in platform/discord_bot/ or set these environment variables:
# Required
DISCORD_BOT_TOKEN=your_discord_bot_token
DISCORD_BOT_API_KEY=your_heimdall_api_key
# Optional (defaults shown)
DISCORD_BOT_API_GRAPHQL_ENDPOINT=http://localhost:3000/v1/gql
DISCORD_BOT_API_REST_ENDPOINT=http://localhost:3000/v1
DISCORD_BOT_API_WEBSOCKET_ENDPOINT=ws://localhost:3000/v1/ws
DISCORD_BOT_API_BIND_ADDRESS=0.0.0.0
DISCORD_BOT_API_BIND_PORT=3006
DISCORD_BOT_RUN_MODE=development
DISCORD_BOT_SENTRY_DSN= # Optional: Sentry error tracking
Environment Variable Reference
| Variable | Required | Default | Description |
|---|---|---|---|
DISCORD_BOT_TOKEN | Yes | - | Discord bot token from Developer Portal |
DISCORD_BOT_API_KEY | Yes | - | Heimdall system API key |
DISCORD_BOT_API_GRAPHQL_ENDPOINT | No | http://localhost:3000/v1/gql | GraphQL endpoint URL |
DISCORD_BOT_API_REST_ENDPOINT | No | http://localhost:3000/v1 | REST API endpoint URL |
DISCORD_BOT_API_WEBSOCKET_ENDPOINT | No | ws://localhost:3000/v1/ws | WebSocket endpoint URL |
DISCORD_BOT_API_BIND_ADDRESS | No | 0.0.0.0 | Health endpoint bind address |
DISCORD_BOT_API_BIND_PORT | No | 3006 | Health endpoint port |
DISCORD_BOT_RUN_MODE | No | development | Config mode: development or production |
DISCORD_BOT_SENTRY_DSN | No | - | Sentry DSN for error tracking |
Running the Bot
Using Just (Recommended)
The project uses just as a command runner:
# Build the bot
just build-dc-bot
# Run the bot
just run-dc-bot
# Run with auto-reload (watches for file changes)
just watch-dc-bot
# Run all checks (format, lint, build)
just verify-dc-bot
Using Cargo Directly
# Navigate to the bot directory
cd platform/discord_bot
# Development mode
cargo run
# Production mode
DISCORD_BOT_RUN_MODE=production cargo run --release
# With specific log level
RUST_LOG=debug cargo run
Docker
# Build stage
FROM rust:1.83 as builder
WORKDIR /app
COPY . .
RUN cargo build --release -p discord_bot
# Runtime stage
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/discord_bot /usr/local/bin/
ENV DISCORD_BOT_RUN_MODE=production
CMD ["discord_bot"]
Verifying the Setup
1. Check Bot Status
Once the bot is running, you should see logs like:
INFO discord_bot::bot::client: Bot is ready!
INFO discord_bot::bot::client: Logged in as Smutje#1234
INFO discord_bot::clients::websocket: Connected to WebSocket
2. Test Commands
In your Discord server, try these commands:
/ping # Should respond with "Pong! 🏓"
/help # Shows available commands
/info # Shows bot information
3. Check Health Endpoint
The bot exposes a health endpoint:
curl http://localhost:3006/health
# Returns: {"status":"healthy","uptime_seconds":123}
4. Verify WebSocket Connection
Check the Heimdall API logs for WebSocket connection:
INFO heimdall_api::websocket: Client connected: discord_bot
Common Issues
Bot Not Responding to Commands
- Check intents: Ensure
MESSAGE_CONTENTintent is enabled in Discord Developer Portal - Check permissions: Bot needs permission to read/send messages in the channel
- Verify token: Make sure
DISCORD_BOT_TOKENis correct
WebSocket Connection Failed
- Check endpoint: Verify
DISCORD_BOT_API_WEBSOCKET_ENDPOINTis correct - Check API key: Ensure
DISCORD_BOT_API_KEYis valid - Check Heimdall API: Ensure the API is running and WebSocket endpoint is available
Commands Not Syncing
Slash commands need to be registered with Discord. This happens automatically on startup, but may take up to an hour to propagate globally. For faster testing:
- Use guild-specific commands (instant)
- Check for registration errors in logs
Permission Denied Errors
- Link Discord account: User must link Discord to their Heimdall account
- Assign roles: User needs roles with required permissions
- Check RBAC: Verify permissions are seeded in Heimdall database
Just Commands Reference
# Building
just build-dc-bot # Build the Discord bot
just build-dc-bot-release # Build in release mode
# Running
just run-dc-bot # Run the Discord bot
just watch-dc-bot # Run with auto-reload on file changes
# Code Quality
just check-dc-bot # Check code without building
just lint-dc-bot # Run clippy lints
just fmt-dc-bot # Format Rust code
just verify-dc-bot # Run all checks (format, lint, check)
# Testing
just test-dc-bot # Run tests
# Protobuf
just proto # Force regenerate Protobuf code
Next Steps
- Configuration - Detailed configuration options
- Commands - Available commands and creating new ones
- Permissions - Setting up RBAC permissions