Prerequisites
Before you begin, ensure you have the following installed:Required Software
-
Rust 1.86 or newer: Install via rustup
-
SQLite: Database engine for local development
- macOS:
brew install sqlite - Ubuntu/Debian:
apt-get install sqlite3 libsqlite3-dev - Windows: Download from sqlite.org
- macOS:
- Git: Version control system
Required Accounts & Keys
- Discord Bot Token: Create a bot at the Discord Developer Portal
- ImgBB API Key: Get a free API key at ImgBB
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:Install SQLx CLI
The SQLx command-line interface is required for database migrations:This installs the SQLx CLI with SQLite support only.
Clone the repository
Clone your fork of the repository (or the main repository):Replace
YOUR-USERNAME with your GitHub username if you’ve forked the repository.Create configuration file
Copy the example environment file:Edit the
.env file with your credentials:.env
Set up the database
Initialize the SQLite database and run all migrations:This command will:
- Create the
database.sqlitefile 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.sqliteBuild the project
Compile the project in debug mode:This downloads all dependencies and compiles the bot. The first build may take several minutes.For a release build with optimizations:
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:Release Mode
For production-like testing with optimizations:Running with Logs
To see detailed logs, set theRUST_LOG environment variable:
error: Only errorswarn: Warnings and errorsinfo: Informational messages (default)debug: Detailed debugging informationtrace: Very detailed trace information
Testing Your Changes
Running Tests
Run the complete test suite:Code Formatting
Format your code according to Rust standards:Linting with Clippy
Run Clippy to catch common mistakes and improve code quality:Discord Bot Setup
To test the bot in Discord:Create a Discord application
- Go to the Discord Developer Portal
- Click “New Application”
- Give your bot a name and create it
Create a bot user
- In your application, go to the “Bot” section
- Click “Add Bot”
- Copy the bot token and add it to your
.envfile
Configure bot permissions
Your bot needs these permissions:
- Read Messages/View Channels
- Send Messages
- Use Slash Commands
- Select scopes:
bot,applications.commands - Select permissions: the ones listed above
- Copy the generated URL
Database Management
Viewing the Database
Use the SQLite CLI to inspect your database:Reset Database
To start fresh with a clean database:Applying New Migrations
When new migrations are added:Common Issues
SQLx compile-time verification fails
SQLx compile-time verification fails
SQLx verifies queries at compile time. If migrations haven’t been run, compilation will fail.Solution:Or set offline mode:
Bot doesn't respond to commands
Bot doesn't respond to commands
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
Database connection errors
Database connection errors
If you see connection errors:Solution:
- Verify
DATABASE_URLin.envis correct - Ensure database file exists and is readable
- Check file permissions on
database.sqlite
Build fails with dependency errors
Build fails with dependency errors
If dependencies fail to download or compile:Solution:
Development Tools
Recommended VS Code Extensions
- 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