Discord companion bot for the A House Divided political simulation β look up politicians, track elections, read in-game news, and more without leaving Discord.
A House Divided is a browser-based political simulation where players create politicians, compete in elections, form coalitions, pass legislation, and climb from state office to national leadership. The game runs on a turn-based economy (1 turn = 1 real hour) with persistent world state across the US and UK.
This repository contains the Discord bot β a companion app that connects to the game's API and exposes live game data via slash commands, so players can check standings, elections, and news without switching to a browser.
| Command | Description | Options |
|---|---|---|
/profile |
View a player's character(s) | name (character name), user (Discord user) |
/leaderboard |
Top politicians by influence or favorability | metric, country, limit |
| Command | Description | Options |
|---|---|---|
/elections |
Active and upcoming elections | country, state |
/election |
Drill into a specific race with candidate standings and vote shares | country, state, race |
/predict |
Projected vs current seat totals with parliament chart | country, race |
/party |
Look up a political party | id (slug, e.g. labour) |
/state |
State or region overview with current officials | id (e.g. CA, UK_ENG) |
| Command | Description | Options |
|---|---|---|
/corporation |
Look up a corporation with tabbed views (overview, bonds, financials) | name |
/bonds |
Browse the bond market across all corporations | corp, page |
/sectors |
Browse sector ownership by industry type | type, unowned, page |
| Command | Description | Options |
|---|---|---|
/news |
Latest in-game news posts | category, limit |
/turn |
Current game turn, year, and clock | β |
| Command | Description | Options |
|---|---|---|
/accept |
Accept the server rules and gain access | β |
/ticket |
Open a support ticket (Bug, Suggestion, or Moderation) | β |
/close-ticket |
Close the current ticket channel (resolution modal; staff must message the opener) | β |
/merge-ticket |
Merge another user's ticket into the current channel (staff only; copies messages, notifies user, deletes source) | user (required) |
/ticket-panel |
Post a persistent ticket panel with buttons | β |
/help |
Browse all bot commands via an interactive select menu | β |
/serverstats |
View server activity graphs | type, days |
/starboard |
Configure the starboard | channel, threshold, emoji, self-star, enabled |
/sync-roles |
Backfill party and country roles for linked members | β |
/version |
Show bot version, commit, and uptime | β |
The bot also sends an automatic welcome message when a new member joins, prompting them to read the rules and run /accept.
| Layer | Technology |
|---|---|
| Bot Framework | discord.js v14 |
| Language | TypeScript 5.3 |
| Runtime | Node.js v20+ |
| Dev Runner | tsx (watch mode) |
| Process Manager | PM2 |
| Game Backend | A House Divided API (hosted remotely) |
adhd-bot/
βββ src/
β βββ commands/
β β βββ accept.ts # /accept (server onboarding)
β β βββ bonds.ts # /bonds (bond market browser)
β β βββ close-ticket.ts # /close-ticket
β β βββ corporation.ts # /corporation (overview/bonds/financials views)
β β βββ election.ts # /election (race detail with interactive drill-down)
β β βββ elections.ts # /elections (list view)
β β βββ help.ts # /help (interactive menu)
β β βββ leaderboard.ts # /leaderboard
β β βββ news.ts # /news
β β βββ party.ts # /party
β β βββ predict.ts # /predict (seat projection with parliament chart)
β β βββ profile.ts # /profile
β β βββ sectors.ts # /sectors
β β βββ serverstats.ts # /serverstats (activity graphs)
β β βββ starboard.ts # /starboard config
β β βββ state.ts # /state
β β βββ sync-roles.ts # /sync-roles
β β βββ ticket-panel.ts # /ticket-panel
β β βββ ticket.ts # /ticket
β β βββ turn.ts # /turn
β β βββ version.ts # /version
β βββ utils/
β β βββ api.ts # Game API client (all fetch functions + types)
β β βββ cooldown.ts # Per-user command cooldown tracker
β β βββ env.ts # Env validation
β β βββ helpRegistry.ts # Help menu command metadata (source of truth)
β β βββ helpers.ts # Shared helpers (hexToInt, errorMessage)
β β βββ starboard.ts # Starboard reaction handler
β β βββ statsStore.ts # Server stats storage
β β βββ tickets.ts # Ticket system utilities
β βββ index.ts # Bot entry point (auto-discovers commands)
β βββ register.ts # Slash command registration (auto-discovers commands)
βββ tests/
β βββ commands/
β β βββ elections.test.ts
β β βββ leaderboard.test.ts
β β βββ party.test.ts
β β βββ state.test.ts
β βββ utils/
β βββ helpers.test.ts
βββ scripts/
β βββ setup.sh # First-time server setup
β βββ deploy.sh # Update & restart bot
βββ ecosystem.config.cjs # PM2 configuration
βββ eslint.config.js # ESLint + typescript-eslint config
βββ vitest.config.ts # Test runner config
βββ .env.example # Required environment variables
βββ tsconfig.json
βββ package.json
- Node.js v20 or later
- npm v10 or later
- A Discord bot token and application from the Discord Developer Portal
- Server Members Intent enabled in the Discord Developer Portal (Bot β Privileged Gateway Intents) β required for the welcome message flow
- A valid
GAME_API_KEYfrom A House Divided
# Clone the repository
git clone https://github.com/Egg3901/adhd-bot.git
cd adhd-bot
# Install dependencies
npm install
# Copy and fill in environment variables
cp .env.example .env| Variable | Description |
|---|---|
DISCORD_BOT_TOKEN |
Your Discord bot token |
DISCORD_CLIENT_ID |
Your Discord application client ID |
GAME_API_URL |
Game API base URL (default: https://www.ahousedividedgame.com/) |
GAME_API_KEY |
API key for the game backend |
WELCOME_CHANNEL_ID |
Channel ID where welcome messages are sent to new members |
RULES_CHANNEL_ID |
Channel ID linked in the welcome message |
MEMBER_ROLE_ID |
Role ID assigned by /accept |
ALPHA_TESTER_ROLE_ID |
Role ID assigned by /accept |
# Run in watch mode (auto-reloads on file changes)
npm run devCommands must be registered with Discord before they appear in servers. Run once per deployment or after adding new commands:
npm run register# Compile TypeScript to dist/
npm run build
# Run compiled output
npm startbash scripts/setup.shThis installs Node.js, PM2, builds the project, registers commands, and starts the bot under PM2 with startup persistence.
bash scripts/deploy.shPulls latest changes, rebuilds, and restarts the PM2 process.
pm2 status # Check bot status
pm2 logs adhd-bot # View live logs
pm2 restart adhd-bot # Manual restart# Run unit tests (pure utility and formatting functions)
npm test
# Watch mode for development
npm run test:watch33 unit tests cover hexToInt, errorMessage, getMetricValue, ideologyLabel, formatElectionType, and formatOfficeType. No mocking required β all tested functions are pure input/output.
Ticket limits: Users can have up to 3 tickets per category at a time.
Ticket merging: Staff can use /merge-ticket inside a ticket channel to merge another user's ticket into it β the source ticket's messages are copied, the user is pinged and DM'd, and the source channel is deleted.
After installing dependencies, run:
# Check for lint errors
npm run lint
# Auto-fix where possible
npm run lint:fix- A House Divided β Main game (Next.js / React / MongoDB)
- AHD Desktop Client β Electron wrapper for native desktop play
Proprietary β All rights reserved.