Configuration File
All configuration is managed through a.env file in the project root. The bot loads this file at startup using the dotenvy library.
Create your
.env file by copying the example:Environment Variables
The following environment variables are used by PFP Checker (defined insrc/util/config.rs):
Your Discord bot token for authentication with the Discord API.How to get it:
- Go to the Discord Developer Portal
- Create a new application or select an existing one
- Navigate to the “Bot” section
- Click “Reset Token” or “Copy” to get your token
Your ImgBB API key for uploading and hosting profile pictures and server icons.How to get it:Example:
- Go to ImgBB API
- Sign up or log in
- Generate an API key from your account settings
ImgBB provides free image hosting with API access. The bot uses this service to archive profile pictures and server icons.
SQLite database file path or connection URL.Format: Examples:
sqlite:<path-to-database-file>The database file will be created automatically if it doesn’t exist (via
create_if_missing: true in src/db/connection.rs:12).Example Configuration
Here’s the complete.env.example file from the repository:
.env.example
Configuration Loading
The configuration is loaded insrc/util/config.rs using the following structure:
src/util/config.rs
All three environment variables are required. The bot will fail to start if any are missing.
Discord Bot Setup
To configure your Discord bot properly, follow these steps:Create a Discord Application
- Go to the Discord Developer Portal
- Click “New Application”
- Give your application a name (e.g., “PFP Checker”)
Create a Bot User
- Navigate to the “Bot” section in the left sidebar
- Click “Add Bot”
- Confirm by clicking “Yes, do it!”
- Copy your bot token and save it securely
Configure Bot Permissions
The bot requires the following permissions:
- Read Messages/View Channels: To see commands
- Send Messages: To respond to commands
- Embed Links: To send rich embeds with profile picture history
- Attach Files: To send image attachments
- Read Message History: To process interactions
The bot uses Gateway Intents: None (as defined in
src/main.rs:379). It relies solely on slash commands and doesn’t need message content or presence intents.ImgBB API Setup
Create an ImgBB Account
Visit ImgBB and sign up for a free account.
Get Your API Key
- Go to ImgBB API
- Navigate to “Get API Key” or your account settings
- Generate a new API key
- Copy the key and add it to your
.envfile
Free Tier Limits: ImgBB’s free tier allows unlimited image uploads with a reasonable rate limit. The bot uses ImgBB to permanently archive profile pictures and server icons.
Database Configuration
Local Development
For local development, use a relative path:.env
database.sqlite in the project root directory.
Docker Deployment
For Docker, the database is stored in a volume:.env
./data directory on your host is mounted to /app/data inside the container, ensuring persistence.
Production Deployment
For production systems, use an absolute path:.env
Database Connection Pool
The bot uses SQLx connection pooling (configured insrc/db/connection.rs):
src/db/connection.rs
Connection Pool
Maximum of 5 concurrent database connections for optimal performance
Auto-creation
Database file is created automatically if it doesn’t exist
Auto-migrations
Migrations run automatically on every startup
Thread-safe
Uses
Arc<Pool> for safe sharing across async tasksSecurity Best Practices
Protecting Your Credentials
-
Never commit
.envfiles.gitignore -
Use environment-specific files
.env.example- Template with placeholder values (safe to commit).env- Actual credentials (never commit).env.production- Production credentials (never commit)
-
Rotate tokens regularly
- Regenerate your Discord bot token periodically
- Update ImgBB API keys if compromised
-
Use restricted permissions
- Only grant the Discord permissions your bot actually needs
- Use separate API keys for development and production
-
Secure file permissions
Environment-Specific Configuration
For different environments, you can use separate env files:Validation and Error Handling
The bot validates configuration at startup (src/main.rs:370):
src/main.rs
- Print an error message
- Exit with a panic
- Not start the Discord connection
Check the logs if the bot fails to start. Common issues include:
- Missing
.envfile - Typos in environment variable names
- Invalid token formats
- Database permission errors
Troubleshooting
Failed to load configuration
Failed to load configuration
Ensure your
.env file exists and contains all required variables:Invalid Discord token
Invalid Discord token
Symptoms:
- Bot fails to connect
- “Unauthorized” errors in logs
- Verify the token is correct (no extra spaces)
- Regenerate the token in Discord Developer Portal
- Ensure the bot user is created in your application
ImgBB upload failures
ImgBB upload failures
Symptoms:
- Images not saving
- HTTP 401 errors
- Verify your ImgBB API key is valid
- Check ImgBB rate limits
- Ensure your account is active
Database connection errors
Database connection errors
Symptoms:
- “unable to open database file”
- Permission denied errors
- Ensure the database directory exists
- Check file permissions:
chmod 755 <directory> - Verify the path in DATABASE_URL is correct
- For Docker, ensure volume mounts are configured
Environment variables not loading in Docker
Environment variables not loading in Docker
Ensure your Or pass variables explicitly:
docker-compose.yml includes the env_file directive:Next Steps
Docker Deployment
Deploy your configured bot using Docker
Manual Installation
Run the bot from source with your configuration