Overview
AutoResponse uses SQLite for data persistence. The bot maintains multiple database files for different purposes, all stored in thedata/ directory.
All databases are created automatically when the bot starts up or when the first relevant command is executed.
Database Files
AutoResponse uses four types of database files:Per-Server Databases
Location:data/{serverId}.db
Each Discord server (guild) has its own database file, named with the server’s Discord ID. These contain server-specific configuration.
Global Databases
| Database | Purpose |
|---|---|
| optoutlist.db | Stores users who opted out of receiving replies |
| leaderboards.db | Tracks reply statistics and seasonal leaderboards |
| replyCooldowns.db | Manages per-channel reply cooldowns |
Server Database Schema
Each server database (initialized incommands/slash/addReplyChannel.js:9) contains three tables:
replyChannels Table
Stores channels where the bot is allowed to send auto-replies.- id - Discord channel ID (primary key)
- chance - Current percentage chance (0-100) of replying to the next message
How the Chance System Works
How the Chance System Works
When a message is sent in a reply channel:
- The bot rolls a random number between 0-100
- If the number is less than or equal to
chance, the bot replies - On reply:
chanceis reset to 6% - On no reply:
chanceincreases by 1% (max 100%)
src/events/messageCreate.js:223.trustedRoles Table
Stores Discord roles that have special permissions or trust levels.- id - Discord role ID (primary key)
phrases Table
Stores trigger phrases that influence bot replies.- phrase - The trigger phrase text (primary key)
Phrases are managed through the
/addphrase and /removephrase commands.Global Database Schemas
optoutlist.db
Location:data/optoutlist.db
Initialized in: src/events/messageCreate.js:17
Stores users who have opted out of receiving auto-replies.
- userId - Discord user ID (primary key)
- userTag - Discord username (unique constraint)
- Users are added via
/optoutcommand - Users are removed via
/optincommand - Checked before every reply in
src/events/messageCreate.js:153
replyCooldowns.db
Location:data/replyCooldowns.db
Initialized in: src/events/messageCreate.js:48
Tracks cooldowns to prevent the bot from replying too frequently in a specific channel.
- serverId - Discord server ID
- channelId - Discord channel ID
- timeRemaining - Unix timestamp when cooldown expires
- Primary Key: Composite of
serverIdandchannelId
- Checked before sending replies to prevent spam
- Retrieved via
getCooldownTimeRemaining()function insrc/events/messageCreate.js:65
leaderboards.db
Location:data/leaderboards.db
Accessed in: commands/slash/leaderboard.js:83
Stores reply statistics and seasonal leaderboards.
Tables:
- current - Current season leaderboard
- Season1 - First season historical data
- Season2 - Second season historical data
- username - Discord username
- replies - Total number of replies received
- groups - Comma-separated list of user groups/badges (e.g., “Owner”, “Programmer”, “Helper”, “S1W”, “S2W”)
Database Initialization
Databases are initialized automatically in different parts of the codebase:Server Databases
Created when a server admin runs configuration commands like:
/addreplychannel/addphrase
initializeDatabase() function.Data Directory Structure
The
data/ directory and all required subdirectories are created automatically if they don’t exist.Database Management
Backup Recommendations
To backup your databases:Manual Database Access
You can inspect databases using the SQLite CLI:Database Migration
Migrating to a New Server
Migrating to a New Server
If you need to move your bot to a new server/machine:
- Stop the bot
- Copy the entire
data/directory to the new location - Ensure file permissions are correct
- Start the bot on the new machine
Clearing Server Data
Clearing Server Data
To remove all data for a specific Discord server:The server’s configuration will be reset. The bot will create a fresh database when configuration commands are run again.
Resetting Opt-Out List
Resetting Opt-Out List
To clear all opt-outs (use with caution):Or delete and recreate:
Troubleshooting
Database Locked Error
Database Locked Error
If you see “database is locked” errors:
- Ensure only one instance of the bot is running
- Check for zombie processes:
ps aux | grep node - Kill any duplicate processes
- Restart the bot
Corrupted Database
Corrupted Database
If a database becomes corrupted:
- Stop the bot
- Restore from backup if available
- Or delete the corrupted database and let the bot recreate it
Missing Tables
Missing Tables
If tables are missing:
- Delete the database file
- Restart the bot
- Run relevant commands to trigger table creation
Permission Errors
Permission Errors
If you see permission errors: