Prerequisites
Ensure you have the following installed on your system:- Rust 1.86 or newer (check with
rustc --version) - SQLite 3.x
- SQLx CLI for database migrations
- Discord Bot Token (Create a bot)
- ImgBB API Key (Get your key)
Rust Version: The project is built with Rust 1.86. Using an older version may result in compilation errors.
Installation Steps
Install SQLx CLI
The SQLx CLI is required for database migrations:
This installs only the SQLite feature to reduce compilation time and dependencies.
Configure environment variables
Create your Edit See the Configuration page for detailed information about each variable.
.env file from the example:.env with your credentials:.env
Set up the database
Create the database and run migrations:This command will:
- Create the SQLite database file
- Run all migration files from the
migrations/directory - Set up the required tables for user tracking, profile pictures, and server icons
Automatic Migrations: When running the bot, migrations are applied automatically on startup via the
establish_connection function in src/db/connection.rs:17.Build the project
Compile the project in release mode for optimal performance:The compiled binary will be located at
./target/release/pfp-checker.Build Time: The first build may take several minutes as Cargo compiles all dependencies. Subsequent builds will be faster.
Project Dependencies
The bot is built with the following key dependencies (fromCargo.toml):
Cargo.toml
Serenity
Discord API library for Rust with full bot support
SQLx
Async, pure Rust SQL library with compile-time checked queries
Tokio
Async runtime for handling concurrent Discord events
Reqwest
HTTP client for uploading images to ImgBB
Database Migrations
The bot includes several migrations that are applied automatically:- 20240506183228_initial.sql: Initial database schema
- 20240908172815_add_username_changes.sql: Username tracking table
- 20241118130945_update_primary_key_of_profile_pictures.sql: Profile picture schema update
- 20251119225006_add_server_tracking.sql: Server icon tracking
- 20251119233447_add_server_picture_index.sql: Performance index for server pictures
Migrations are embedded in the binary and run automatically on startup. No manual intervention is needed.
Running as a System Service
For production deployments, you can run the bot as a systemd service.Create a systemd service file
Create
/etc/systemd/system/pfp-checker.service:/etc/systemd/system/pfp-checker.service
Managing the Service
Development Mode
For development, you can run the bot without building:Development builds (
cargo run without --release) are significantly slower at runtime but compile faster. Use --release for production.Updating the Bot
To update to the latest version:Run database migrations
This step is optional as migrations run automatically on startup, but it’s good practice to run them manually to catch any issues early.
Troubleshooting
Compilation errors
Compilation errors
Ensure you’re using Rust 1.86 or newer:Clean the build cache and rebuild:
SQLx CLI installation fails
SQLx CLI installation fails
If you encounter errors installing SQLx CLI, ensure you have the necessary system dependencies:Ubuntu/Debian:macOS:
Database migration errors
Database migration errors
If migrations fail, check your DATABASE_URL:If the database is corrupted, you can reset it:
Bot fails to connect to Discord
Bot fails to connect to Discord
Verify your Discord token is valid:
- Check your
.envfile for the correct token - Ensure there are no extra spaces or quotes
- Verify the bot is not already running elsewhere
- Check Discord’s status page for API issues
Permission denied when running binary
Permission denied when running binary
Make the binary executable:
Next Steps
Configuration
Learn about all available environment variables and configuration options
Docker Deployment
Prefer containerized deployment? Check out the Docker guide