Skip to main content

Overview

The set-xp command allows administrators to manually adjust a user’s XP (experience points) value. The command automatically calculates and updates the corresponding level based on the XP amount.
This command requires staff role permissions or administrator status. It should be used carefully as it directly modifies user progression data.

Command Signature

/set-xp <user> <xp>

Parameters

user
User
required
The Discord user whose XP you want to modify
xp
Integer
required
The new XP value to set for the user (must be a positive integer)

Permissions Required

This command uses a custom permission check (executor_is_dev_or_admin) that requires one of:
  • Semester Moderator Role (configured in bot settings)
  • Staff Role (configured in bot settings)
  • Administrator permission on Discord

Usage Examples

Set a user’s XP to 500

/set-xp @student123 500
Response:
Set XP of @student123 to 500

Reset a user’s XP to 0

/set-xp @john_doe 0

Level Calculation

The bot automatically calculates the user’s level based on their XP using this formula:
level = floor(xp / 100)
For example:
  • 0-99 XP = Level 0
  • 100-199 XP = Level 1
  • 500-599 XP = Level 5
  • 1000-1099 XP = Level 10

Implementation Details

Source reference: src/commands/administration.rs:114-172

Database Operations

The command performs the following operations:
  1. Checks if the user exists in the user_xp table
  2. If the user exists: Updates their XP and recalculates their level
  3. If the user doesn’t exist: Creates a new entry with the specified XP and calculated level

SQL Queries

Update existing user:
UPDATE user_xp SET user_xp = $1, user_level = $2 WHERE user_id = $3
Insert new user:
INSERT INTO user_xp (user_id, user_xp, user_level) VALUES ($1, $2, $3)

Use Cases

  • Correcting XP after a bug or error
  • Rewarding users for special contributions
  • Resetting XP as part of a moderation action
  • Setting up test accounts with specific XP levels

Build docs developers (and LLMs) love