Skip to main content

Prerequisites

Before you begin developing Faculty Bot, ensure you have the following tools installed:

Required Tools

1

Install Rust Toolchain

Faculty Bot requires the Rust programming language (stable channel):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Choose the stable toolchain during installation.
2

Install PostgreSQL

The bot uses PostgreSQL 13+ as its database:
  • macOS: brew install postgresql@13
  • Ubuntu/Debian: sudo apt install postgresql-13
  • Windows: Download from postgresql.org
3

Install Development Dependencies

Additional build dependencies for the Rust ecosystem:Linux (Ubuntu/Debian):
sudo apt install build-essential pkg-config libssl-dev
macOS:
xcode-select --install

Project Setup

1

Clone the Repository

git clone <repository-url>
cd faculty_manager
2

Configure Environment Variables

Create a .env file in the project root:
.env
DISCORD_TOKEN=your_discord_bot_token_here
DATABASE_URL=postgres://faculty_manager:password@localhost/faculty_manager
PREFIX=>

# Email configuration for verification
SEND_FROM_ADDRESS=[email protected]
MAIL_USERNAME=your_mail_username
MAIL_PASSWORD=your_mail_password
SMTP_SERVER=smtp.example.com
SMTP_PORT=587

# Optional: Logging configuration
RUST_LOG="info,sqlx=error,sqlx::query=error,sqlx::query_as=error"

# Optional: InfluxDB for metrics
INFLUX_TOKEN=your_influx_token
3

Set Up the Database

Initialize the PostgreSQL database:
# Create database and user
psql -U postgres
CREATE DATABASE faculty_manager;
CREATE USER faculty_manager WITH PASSWORD 'averysecurepasswordyes';
GRANT ALL PRIVILEGES ON DATABASE faculty_manager TO faculty_manager;
\q

# Run migrations
psql -U faculty_manager -d faculty_manager -f migrations/faculty_manager.sql
4

Configure the Bot

Edit config.json with your Discord server settings:
config.json
{
  "prefix": ">",
  "roles": {
    "staffrole": 123456789,
    "verified": 123456789,
    "mealplannotify": 123456789,
    "semestermodrole": 123456789
  },
  "channels": {
    "logs": 123456789,
    "greetings": 123456789,
    "news": 123456789,
    "xp": 123456789,
    "rules": 123456789,
    "ads": 123456789,
    "createChannel": "Create Channel",
    "mealplan": 123456789
  },
  "general": {
    "adstimeout": 86400000,
    "chars_for_level": 100,
    "xp_scaling_factor": 0.1
  },
  "mealplan": {
    "post_mealplan": false,
    "url": "https://example.com/mealplan.pdf",
    "check": 60,
    "post_on_day": "Monday",
    "post_at_hour": "18:00:00"
  }
}

Building the Project

Development Build

For faster compilation during development:
cargo build
The binary will be available at target/debug/faculty_manager.

Release Build

For production deployment with optimizations:
cargo build --release
The optimized binary will be at target/release/faculty_manager.

Running Locally

Standard Run

cargo run

With Logging

Enable detailed logging for debugging:
RUST_LOG=debug cargo run

Watch Mode (Auto-rebuild)

Install cargo-watch for automatic rebuilds on file changes:
cargo install cargo-watch
cargo watch -x run

Discord Bot Setup

1

Create a Discord Application

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

Create a Bot User

  1. Navigate to the “Bot” tab
  2. Click “Add Bot”
  3. Copy the token and add it to your .env file as DISCORD_TOKEN
3

Configure Bot Permissions

Enable the following in the “Bot” tab:
  • Presence Intent
  • Server Members Intent
  • Message Content Intent
4

Invite Bot to Server

  1. Go to “OAuth2” > “URL Generator”
  2. Select scopes: bot, applications.commands
  3. Select permissions:
    • Manage Roles
    • Manage Channels
    • Send Messages
    • Manage Messages
    • Embed Links
    • Attach Files
    • Read Message History
    • Add Reactions
    • Use Slash Commands
  4. Copy the generated URL and open it in your browser

Registering Slash Commands

Once the bot is running, register slash commands globally:
# In Discord, with MANAGE_GUILD permission:
>register
Or wait for automatic registration on bot startup (configured in main.rs:235).

Development Tools

Rust Analyzer

Install the Rust Analyzer extension for your IDE:
  • VS Code: rust-lang.rust-analyzer
  • IntelliJ: Rust plugin

Database Tools

pgAdmin or DBeaver for PostgreSQL management:
# Connect to local database
Host: localhost
Port: 5432
Database: faculty_manager
User: faculty_manager

Useful Cargo Commands

# Check code without building
cargo check

# Run tests
cargo test

# Format code
cargo fmt

# Lint code
cargo clippy

# Update dependencies
cargo update

Docker Development (Alternative)

For containerized development:
# Start database only
docker-compose -f docker_db.yml up -d

# Or full stack
docker-compose up

Troubleshooting

Build Errors

Error: failed to run custom build command for rosetta-build Solution: Ensure all translation files exist in i18n/ directory (en.json, de.json, ja.json).

Database Connection Issues

Error: error connecting to database Solution: Verify PostgreSQL is running and credentials in .env are correct:
psql -U faculty_manager -d faculty_manager

Discord Token Issues

Error: Expected DISCORD_TOKEN in the environment Solution: Ensure .env file exists and contains a valid DISCORD_TOKEN.

Next Steps

Build docs developers (and LLMs) love