Quickstart Guide
This guide will help you get Template Worker up and running quickly. By the end, you’ll have a working worker pool that can execute templates and handle Discord events.This quickstart assumes you have Rust, PostgreSQL, and basic familiarity with Discord bots. For production deployments, see the Deployment guides.
Prerequisites
Before you begin, ensure you have:- Rust (1.70 or later) - Install Rust
- PostgreSQL (14 or later) - Running database instance
- Discord Bot Token - From the Discord Developer Portal
- Object Storage - S3-compatible storage or local filesystem
- Sandwich Gateway (optional) - For production Discord gateway proxy
git clone https://github.com/Anti-Raid/template-worker.git
cd template-worker
cargo build --release
discord_auth:
token: "YOUR_BOT_TOKEN"
client_id: "YOUR_CLIENT_ID"
client_secret: "YOUR_CLIENT_SECRET"
root_users:
- "123456789012345678" # Your Discord user ID
allowed_redirects:
- "http://localhost:3000"
meta:
postgres_url: "postgresql://user:password@localhost/antiraid"
proxy: "http://localhost:8080" # Or your proxy URL
support_server_invite: "https://discord.gg/your-invite"
sandwich_http_api: "http://localhost:8000" # Sandwich gateway API
default_error_channel: "1234567890" # Channel ID for error logs
object_storage:
type: "local" # Use "s3-like" for production
base_path: "./data/storage"
# For S3-compatible storage:
# type: "s3-like"
# endpoint: "s3.amazonaws.com"
# access_key: "YOUR_ACCESS_KEY"
# secret_key: "YOUR_SECRET_KEY"
# secure: true
# cdn_endpoint: "cdn.example.com"
# cdn_secure: true
sites:
api: "http://localhost:3030"
frontend: "http://localhost:3000"
docs: "https://docs.antiraid.xyz"
servers:
main: "1234567890" # Your main guild ID
addrs:
template_worker: "0.0.0.0:3030" # Public API address
mesophyll_server: "127.0.0.1:0" # Mesophyll coordination (random port)
(template_worker) INFO - Connecting to database
(migrations) INFO - Applying migration: tenantstate
(migrations) INFO - Applying migration: kv_generic
(migrations) INFO - All migrations applied successfully
This reads the built-in command definitions and registers them globally with Discord’s API. Commands will be available within an hour (or instantly in your development guild).
WorkerThread instancesfauxpas> print("Hello from Template Worker!")
Hello from Template Worker!
fauxpas> local result = 2 + 2
fauxpas> print(result)
4
fauxpas> -- Access built-in functions
fauxpas> local discord = require("@antiraid/discord")
fauxpas> print(discord.version)
Configuration Options
Template Worker accepts several command-line arguments to customize behavior:Common Arguments
Process Pool Specific
Example Configurations
Development setup:Verify the Installation
Once your worker is running, verify everything works:Check the API
The worker exposes an HTTP API (default port 3030):View OpenAPI Documentation
Template Worker includes interactive API documentation at:- Request/response schemas
- Authentication requirements
- Example payloads
- Try-it-out functionality
Check Logs
The worker logs important events to stdout:Worker processes log with
[Worker N] prefixes to distinguish output from different workers.Understanding Worker Modes
Template Worker supports six different operational modes:Next Steps
Now that you have Template Worker running, explore:Architecture Overview
Learn how the worker system is designed
Worker System Deep Dive
Understand WorkerLike, pools, and topologies
Configuration Guide
Complete configuration reference
API Reference
Explore the HTTP and WebSocket APIs
Troubleshooting
Database Connection Errors
If you see connection errors:- Verify PostgreSQL is running:
psql -U user -d antiraid - Check the connection string in
config.yaml - Ensure the database exists:
createdb antiraid - Verify network access if using remote database
Discord Authentication Errors
If the bot can’t authenticate:- Verify your bot token is correct
- Check that the bot has required intents enabled
- Ensure the client ID matches your application
- Confirm the bot is added to at least one guild
Compilation Errors
If the build fails:- Update Rust:
rustup update - Clean build artifacts:
cargo clean - Check Cargo.toml dependencies are accessible
- Ensure you have required system libraries
Worker Startup Issues
If workers fail to start:- Check logs for specific error messages
- Verify all config.yaml fields are filled
- Ensure ports are not already in use
- Check file permissions for object storage path