Skip to main content

Prerequisites

Before you begin, ensure you have the following installed:

Required Software

  • Rust 1.86 or newer: Install via rustup
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
  • SQLite: Database engine for local development
    • macOS: brew install sqlite
    • Ubuntu/Debian: apt-get install sqlite3 libsqlite3-dev
    • Windows: Download from sqlite.org
  • Git: Version control system

Required Accounts & Keys

ImgBB is used to host profile picture and server icon images for historical tracking.

Installation Steps

Follow these steps to set up your development environment:
1

Install SQLx CLI

The SQLx command-line interface is required for database migrations:
cargo install sqlx-cli --no-default-features --features sqlite
This installs the SQLx CLI with SQLite support only.
2

Clone the repository

Clone your fork of the repository (or the main repository):
git clone https://github.com/YOUR-USERNAME/pfp-checker.git
cd pfp-checker
Replace YOUR-USERNAME with your GitHub username if you’ve forked the repository.
3

Create configuration file

Copy the example environment file:
cp .env.example .env
Edit the .env file with your credentials:
.env
DISCORD_TOKEN=your_discord_bot_token_here
IMGBB_KEY=your_imgbb_api_key_here
DATABASE_URL=sqlite:database.sqlite
Never commit your .env file to version control. It contains sensitive credentials.
4

Set up the database

Initialize the SQLite database and run all migrations:
sqlx database setup --database-url sqlite:database.sqlite
This command will:
  • Create the database.sqlite file if it doesn’t exist
  • Run all migration files from the migrations/ directory
  • Set up the complete schema with all tables and indexes
If you need to reset the database later, use sqlx database reset --database-url sqlite:database.sqlite
5

Build the project

Compile the project in debug mode:
cargo build
This downloads all dependencies and compiles the bot. The first build may take several minutes.For a release build with optimizations:
cargo build --release
6

Run the tests

Verify your setup by running the test suite:
cargo test
All tests should pass. If any fail, check your configuration and database setup.

Running the Bot Locally

Once your environment is set up, you can run the bot:

Development Mode

Run the bot with debug information and faster compilation:
cargo run
You should see output like:
BotName is connected!
Updated Global Application Commands

Release Mode

For production-like testing with optimizations:
cargo run --release

Running with Logs

To see detailed logs, set the RUST_LOG environment variable:
RUST_LOG=debug cargo run
Log levels:
  • error: Only errors
  • warn: Warnings and errors
  • info: Informational messages (default)
  • debug: Detailed debugging information
  • trace: Very detailed trace information

Testing Your Changes

Running Tests

Run the complete test suite:
cargo test
Run specific tests:
cargo test test_name
Run tests with output:
cargo test -- --nocapture

Code Formatting

Format your code according to Rust standards:
cargo fmt
Check formatting without making changes:
cargo fmt -- --check

Linting with Clippy

Run Clippy to catch common mistakes and improve code quality:
cargo clippy
For more strict checking:
cargo clippy -- -D warnings

Discord Bot Setup

To test the bot in Discord:
1

Create a Discord application

  1. Go to the Discord Developer Portal
  2. Click “New Application”
  3. Give your bot a name and create it
2

Create a bot user

  1. In your application, go to the “Bot” section
  2. Click “Add Bot”
  3. Copy the bot token and add it to your .env file
Keep your bot token secret! Reset it immediately if it’s ever exposed.
3

Configure bot permissions

Your bot needs these permissions:
  • Read Messages/View Channels
  • Send Messages
  • Use Slash Commands
In the “OAuth2” > “URL Generator” section:
  1. Select scopes: bot, applications.commands
  2. Select permissions: the ones listed above
  3. Copy the generated URL
4

Invite the bot to a test server

  1. Use the URL from the previous step
  2. Select a Discord server where you have admin permissions
  3. Authorize the bot
Create a private test server for development to avoid disrupting real users.

Database Management

Viewing the Database

Use the SQLite CLI to inspect your database:
sqlite3 database.sqlite
Useful SQLite commands:
-- List all tables
.tables

-- Show table schema
.schema User

-- Query data
SELECT * FROM User;

-- Exit SQLite
.exit

Reset Database

To start fresh with a clean database:
sqlx database reset --database-url sqlite:database.sqlite
This will delete all data! Use with caution.

Applying New Migrations

When new migrations are added:
sqlx migrate run --database-url sqlite:database.sqlite

Common Issues

SQLx verifies queries at compile time. If migrations haven’t been run, compilation will fail.Solution:
sqlx database setup --database-url sqlite:database.sqlite
Or set offline mode:
export SQLX_OFFLINE=true
Common causes:
  • Bot token is incorrect
  • Bot lacks necessary permissions
  • Commands haven’t been registered (wait ~1 minute after startup)
  • Bot is not in the server
Solution: Check logs for error messages and verify bot permissions.
If you see connection errors:Solution:
  1. Verify DATABASE_URL in .env is correct
  2. Ensure database file exists and is readable
  3. Check file permissions on database.sqlite
If dependencies fail to download or compile:Solution:
# Update Rust
rustup update

# Clean build cache
cargo clean

# Rebuild
cargo build

Development Tools

  • rust-analyzer: Rust language support with excellent IDE features
  • Even Better TOML: Better support for Cargo.toml
  • CodeLLDB: Debugging support for Rust
  • crates: Manage Cargo.toml dependencies

Alternative IDEs

  • IntelliJ IDEA / CLion: With Rust plugin
  • Vim/Neovim: With rust-analyzer via LSP
  • Emacs: With rust-mode and rust-analyzer

Next Steps

Now that your development environment is set up:

Architecture Guide

Learn how the codebase is structured

Database Schema

Understand the database design

Contributing Guidelines

Review contribution workflow

Commands Reference

See all available bot commands

Build docs developers (and LLMs) love