A Discord bot for managing Kingdoms & Warfare campaigns, built on Cloudflare Workers. This bot provides comprehensive tools for managing domains, units, battles, and intrigue sessions from the MCDM Productions' Kingdoms & Warfare supplement for Dungeons & Dragons 5th Edition.
- Domain Management: Create and manage political domains with skills, defenses, and resources
- Unit Management: Create and track military units with stats, conditions, and traits
- Battle System: Run warfare battles with unit deployment, initiative tracking, and combat resolution
- Intrigue System: Conduct political intrigue sessions with skill tests and domain actions
- Dice Rolling: Specialized dice rolling for warfare and intrigue mechanics
- Reference Information: Quick access to rules and reference information
├── src
│ ├── commands.js -> Command registration
│ ├── register.js -> Sets up commands with Discord API
│ ├── server.js -> Main server and request handling
│ ├── knw/ -> Kingdoms & Warfare specific code
│ │ ├── commands/ -> Command handlers
│ │ │ ├── warfare/ -> Warfare command implementations
│ │ │ └── intrigue/ -> Intrigue command implementations
│ │ ├── models/ -> Data models
│ │ └── utils/ -> Utility functions
│ │ ├── dice.js -> Dice rolling utilities
│ │ ├── formatter.js -> Message formatting utilities
│ │ ├── storage.js -> Storage interface (backward compatibility)
│ │ └── storage/ -> Modular storage system
│ │ ├── core.js -> Core storage functions
│ │ ├── unit.js -> Unit storage
│ │ ├── domain.js -> Domain storage
│ │ ├── battle.js -> Battle storage
│ │ ├── intrigue.js -> Intrigue storage
│ │ ├── discord.js -> Discord-related storage
│ │ └── index.js -> Main entry point
├── wrangler.toml -> Cloudflare Workers configuration
└── package.json
- Node.js (v18 or higher)
- npm (usually comes with Node.js)
- Wrangler CLI for Cloudflare Workers
- A Discord Developer Account
- Go to the Discord Developer Portal
- Click "New Application" and give it a name (e.g., "DIS Kingdom")
- Navigate to the "Bot" tab and click "Add Bot"
- Under the "Privileged Gateway Intents" section, enable any necessary intents
- Under the "Token" section, click "Reset Token" and copy the new token (you'll need this later)
- Navigate to the "OAuth2" tab
- Under "OAuth2 URL Generator", select the following scopes:
applications.commandsbot
- Under "Bot Permissions", select:
Send MessagesUse Slash CommandsEmbed Links(for formatted messages)
- Copy the generated URL and open it in a browser to add the bot to your server
- Create a Cloudflare account if you don't have one
- Navigate to the Workers section
- Create a new Worker with the name "diskingdom" (or your preferred name)
- Create a new KV Namespace:
- Go to "KV" under Workers
- Click "Create namespace"
- Name it "KNW_DATA"
- Copy the Namespace ID (you'll need this for configuration)
-
Clone this repository:
git clone https://github.com/yourusername/diskingdom.git cd diskingdom -
Install dependencies:
npm install -
Configure environment variables:
- Rename
example.dev.varsto.dev.vars - Add your Discord credentials:
DISCORD_TOKEN=your_bot_token DISCORD_PUBLIC_KEY=your_public_key DISCORD_APPLICATION_ID=your_application_id
- Rename
-
Update the KV namespace ID in
wrangler.toml:kv_namespaces = [ { binding = "KNW_DATA", id = "your-kv-namespace-id-here" } ]
Register the bot's commands with Discord:
npm run register
-
Start the local development server:
npm start -
In a separate terminal, start ngrok to create a tunnel:
npm run ngrok -
Copy the HTTPS URL provided by ngrok (e.g.,
https://1234-56-78-910-11.ngrok.io) -
Update your Discord application's "Interactions Endpoint URL" in the Discord Developer Portal:
- Go to your application
- Navigate to "General Information"
- Paste the ngrok URL in the "Interactions Endpoint URL" field
- Add
/to the end of the URL (e.g.,https://1234-56-78-910-11.ngrok.io/) - Click "Save Changes"
-
Configure Cloudflare Worker secrets:
wrangler secret put DISCORD_TOKEN wrangler secret put DISCORD_PUBLIC_KEY wrangler secret put DISCORD_APPLICATION_ID -
Deploy to Cloudflare Workers:
npm run publish -
Update your Discord application's "Interactions Endpoint URL" to your Cloudflare Worker URL:
- Go to your application in the Discord Developer Portal
- Navigate to "General Information"
- Update the "Interactions Endpoint URL" with your Worker URL (e.g.,
https://diskingdom.yourusername.workers.dev/) - Click "Save Changes"
/warfare unit create- Create a new military unit/warfare unit view- View details of a unit/warfare unit list- List all units/warfare battle create- Create a new battle/warfare battle add_domain- Add a domain to a battle/warfare battle add_unit- Add a unit to a battle/warfare battle deploy_unit- Deploy a unit on the battlefield/warfare battle start- Start a battle/warfare roll attack- Roll an attack/warfare roll damage- Roll damage
/intrigue domain create- Create a new domain/intrigue domain view- View details of a domain/intrigue domain list- List all domains/intrigue session create- Create a new intrigue session/intrigue session action- Take an action in an intrigue session/intrigue roll- Roll a domain skill check/intrigue reference- Get reference information
The bot uses a modular storage system that supports both in-memory storage (for development) and Cloudflare KV storage (for production). The storage system is organized into the following components:
core.js- Core storage functionsunit.js- Unit-specific storagedomain.js- Domain-specific storagebattle.js- Battle-specific storageintrigue.js- Intrigue-specific storagediscord.js- Discord-specific storage (server, channel, user)index.js- Main entry point that exports all storage functions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- MCDM Productions for creating Kingdoms & Warfare
- Discord.js for the Discord API wrapper
- Cloudflare Workers for hosting