A powerful, self-hosted Discord bot platform built with SvelteKit 2 (Svelte 5) and deployed on Cloudflare Pages. Create custom slash commands, build event-driven automations, and monitor all Discord activity through a beautiful admin dashboard.
- Custom Slash Commands โ Create your own commands with parameters, choices, and custom responses
- Event-Driven Automations โ Trigger actions automatically when Discord events occur
- Full Gateway Support โ Real-time event capture via Discord.js gateway connection
- Interactions Endpoint โ HTTP-based slash command handling via Cloudflare Workers
- Context Menu Commands โ Message context menu registration and routing with server-side permission enforcement
- AI Chat for Managers โ Server managers can DM the bot for AI-powered
assistance. In production this runs on Cloudflare Workers AI (optionally
through an AI Gateway for analytics/caching); in local development you can
point it at an Ollama model instead (
AI_PROVIDER=ollama, defaultgemma3:4b). - AI DM Autopilot โ When enabled, gateway DMs are enqueued onto a Cloudflare Queue and handled by a standalone orchestrator worker (see docs/ai-autopilot.md).
- Server Selection โ Manage all servers where you're an admin
- Event Logs โ View detailed logs of all Discord activity (members, messages, voice, moderation, etc.)
- Automation Builder โ Visual interface to create event โ action automations
- Command Builder โ Design custom slash commands with the automation action system
- Dark/Light Theme โ Beautiful UI with theme toggle support
- Operational UX โ Global toasts, skeleton loading states, route-level error handling, and reduced-motion-aware transitions
- Local Runner โ A standalone Bun CLI users install on their own machine. It connects to the server over WebSocket, runs jobs as shell commands inside a path allowlist, and streams results back (see docs/local-runner-v2.md).
- Superadmin Workflows โ Scheduled, server-spanning workflow templates driven
by
cron_expressionvalues stored in D1 (see docs/superadmin-workflows.md). - MCP Server โ A standalone Model Context Protocol server (
mcp-server/) that exposes SpaceBot data/operations to MCP-aware clients.
- Discord OAuth2 โ Secure login with Discord credentials
- Sliding Session TTL โ Configurable cookie lifetime via
SESSION_TTL_SECONDS - Admin Access Control โ Only server admins can manage their servers
- Request Signature Verification โ All Discord interactions are cryptographically verified
- Browser Hardening โ Same-origin checks for cookie-authenticated JSON mutations plus HTML security headers and report-only CSP
- Cloudflare Pages โ Deployed on Cloudflare's global edge network
- D1 Database โ SQLite-based serverless database for logs and configurations
- Workers AI โ AI-powered DM responses via Cloudflare's free LLM models
- AI Gateway โ Optional analytics, caching, and rate limiting for AI requests
- Zero Cold Starts โ Fast response times worldwide
Repository-ready external integrations are configured with environment variables, not hardcoded credentials:
PUBLIC_SUPPORT_DISCORD_URL,PUBLIC_BOT_VOTE_URL, andPUBLIC_BOT_REVIEW_URLpower public community CTAs.SENTRY_DSN,SENTRY_ENVIRONMENT, andSENTRY_TRACES_SAMPLE_RATEenable Sentry.RATE_LIMIT_ENABLED,RATE_LIMIT_DEFAULT_WINDOW_SECONDS, andRATE_LIMIT_DEFAULT_MAX_REQUESTSenable D1-backed API limits.
Useful checks:
bun run docs:api
bun run audit:deps
bun run images:check
bun run verify:http3๐ Server Admin (Dark Mode)
View event logs, statistics, and quick access to automations and commands.
โก Automations
Create event-driven automations that trigger on Discord events like member joins, message creates, voice state changes, and more.
๐ ๏ธ Automation Editor
Visual interface for configuring triggers, conditions, and actions for your automations.
๐ฎ Custom Commands
Build custom slash commands with parameters and tie them to automation actions.
โ๏ธ Command Editor
Design slash commands with options, parameters, and custom responses through an intuitive editor.
| Layer | Technology |
|---|---|
| Framework | SvelteKit 2 (Svelte 5) |
| Edge runtime | Cloudflare Pages/Workers |
| Package manager | Bun |
| Database | Cloudflare D1 (SQLite) |
| Bot Library | Discord.js 14 |
| AI | Cloudflare Workers AI / AI Gateway (prod); Ollama (dev only) |
| Styling | Custom CSS with CSS Variables |
| Auth | Discord OAuth2 |
- Bun 1.3+ (the project's package manager and runtime โ used for every script; Node.js is not required)
- A Discord Application (create one here)
- A Cloudflare account (sign up here)
- (Optional) cloudflared for local tunneling
-
Clone the repository
git clone https://github.com/starspacegroup/spacebot.git cd spacebot -
Install dependencies
bun install
-
Configure environment variables
Copy
.env.exampleto.envand fill in your Discord credentials:cp .env.example .env
Required variables:
Variable Description DISCORD_PUBLIC_KEYFound in your app's "General Information" DISCORD_CLIENT_IDYour application's Client ID DISCORD_CLIENT_SECRETFound under OAuth2 settings DISCORD_BOT_TOKENFound under "Bot" settings ADMIN_USER_IDSComma-separated Discord user IDs with global admin access LOG_LEVELLogging verbosity: error,warn,info,debugOptional AI variables (for DM chat functionality):
Variable Description CLOUDFLARE_ACCOUNT_IDYour Cloudflare account ID CLOUDFLARE_AI_TOKENAPI token with Workers AI permissions CLOUDFLARE_AI_GATEWAY_ID(Optional) AI Gateway ID for analytics/caching CLOUDFLARE_AI_MODEL(Optional) Override default LLM model -
Set up the database (local development)
bun run db:migrate:local
-
Run the development server
bun run dev
The app will be available at
http://localhost:4269(the port is pinned invite.config.js). -
Start the Gateway bot (in a separate terminal)
bun run dev:gateway
This captures Discord events and processes automations.
- Go to Discord Developer Portal
- Select your application โ Bot
- Enable Privileged Gateway Intents:
- โ Presence Intent
- โ Server Members Intent
- โ Message Content Intent
- Go to OAuth2 โ URL Generator
- Scopes:
bot,applications.commands - Permissions: Administrator (or customize as needed)
- Scopes:
- Use the generated URL to invite the bot to your server
For production, configure Discord to send interactions to your Cloudflare Pages URL:
- Deploy to Cloudflare Pages (see Deployment)
- Go to Discord Developer Portal โ Your Application โ General Information
- Set Interactions Endpoint URL to:
https://your-domain.pages.dev/api/discord/interactions
| Script | Description |
|---|---|
bun run dev |
Start SvelteKit dev server |
bun run dev:wrangler |
Run with Wrangler (Cloudflare local environment) |
bun run dev:gateway |
Start Discord gateway bot |
bun run dev:tunnel |
Start cloudflared tunnel for local development |
bun run build |
Build for production |
bun run db:migrate |
Run database migrations (production) |
bun run db:migrate:local |
Run database migrations (local) |
bun run register-commands |
Register slash commands with Discord |
bun run test |
Run the Vitest test suite |
bun run test:e2e |
Run the Playwright smoke suite |
bun run typecheck |
Type-check with svelte-check |
bun run lint |
Run ESLint |
bun run runner |
Start the local runner CLI |
SpaceBot's automation engine lets you create powerful event-driven workflows:
- Member Events โ Join, leave, ban, unban, kick, timeout
- Message Events โ Create, edit, delete, bulk delete
- Voice Events โ Join, leave, mute, deafen, stream, video
- Role Events โ Create, delete, update, member role add/remove
- Channel Events โ Create, delete, update
- Reaction Events โ Add, remove
- Interaction Events โ Slash commands, button clicks, modals
- And many more...
- ๐จ Send Message โ Send a message to a channel
- ๐๏ธ Delete Messages โ Delete messages from a user
- ๐๏ธ Delete Messages Mentioning User โ Delete messages that mention a specific user
- ๐ท๏ธ Add/Remove Role โ Modify member roles
- ๐ข Kick Member โ Kick a member from the server
- ๐จ Ban Member โ Ban a member
- โฐ Timeout Member โ Timeout a member
- ๐ข Send DM โ Send a direct message to a user
Use dynamic variables in your messages:
Welcome {user.mention} to {guild.name}!
Available: {user.id}, {user.name}, {user.mention}, {channel.name},
{guild.name}, {option.<name>}, and more.
Create custom slash commands through the web dashboard:
- Navigate to Admin โ Your Server โ Commands
- Click New Command
- Configure:
- Command name and description
- Parameters (text, numbers, users, channels, roles, etc.)
- Response message or embed
- Optional: Tie to an automation action
- Click Register with Discord to sync
SpaceBot captures and logs all Discord events:
| Category | Events |
|---|---|
| ๐ค Member | Join, leave, update, nickname changes |
| ๐ฌ Message | Create, edit, delete, bulk delete |
| ๐ค Voice | Join, leave, mute, deafen, stream, video |
| ๐ Channel | Create, delete, update |
| ๐ท๏ธ Role | Create, delete, update, member assignments |
| ๐จ Moderation | Ban, unban, kick, timeout |
| โก Interaction | Commands, buttons, modals, select menus |
| ๐ Events | Scheduled event create, update, delete |
-
Push to GitHub
git push origin main
-
Connect to Cloudflare Pages
- Go to Cloudflare Dashboard
- Workers & Pages โ Create application โ Pages โ Connect to Git
- Select your repository
- Configure:
- Build command:
bun run build - Build output:
.svelte-kit/cloudflare
- Build command:
-
Add Environment Variables In Cloudflare Pages Settings โ Environment Variables, add all required variables.
-
Create D1 Database
wrangler d1 create spacebot-logs
Update
wrangler.tomlwith the database ID. -
Run Migrations
bun run db:migrate
-
Deploy Future pushes to
mainwill auto-deploy.AI queue orchestration also auto-deploys via GitHub Actions in
.github/workflows/deploy-orchestrator-worker.yml. Configure these repository secrets so worker deploys can run:CLOUDFLARE_API_TOKENCLOUDFLARE_ACCOUNT_IDORCHESTRATOR_SPACEBOT_API_BASEAI_AUTOPILOT_INTERNAL_KEY
See DEPLOYMENT.md for detailed instructions.
spacebot/
โโโ src/
โ โโโ lib/
โ โ โโโ ai/ # AI chat, MCP client, retry policy
โ โ โโโ automation/ # Event โ action automation engine
โ โ โโโ components/ # Svelte components
โ โ โโโ db/ # D1/SQLite access, one module per domain
โ โ โโโ discord/ # Gateway client, REST, bot registry, commands
โ โ โโโ integrations/ # External integrations (e.g. GitHub) + auth
โ โ โโโ server/ # Server-only helpers (cron, workflow runtime)
โ โ โโโ utils/ # Shared utilities
โ โโโ routes/
โ โ โโโ admin/ # Per-server dashboard (under [serverId]/)
โ โ โโโ account/ # User-level AI jobs / workflows / operations
โ โ โโโ api/ # REST endpoints (+ api/v1, api/runner/ws)
โ โโโ tests/ # Vitest test suites
โ โโโ hooks.server.ts # Edge auth + request handling
โโโ orchestrator-worker/ # Cloudflare Queue consumer (AI autopilot, cron)
โโโ mcp-server/ # Standalone MCP server
โโโ scripts/ # CLIs and tooling (incl. scripts/local-runner/)
โโโ migrations/ # D1 database migrations (immutable once applied)
โโโ _functions/ # Cloudflare Pages Functions
โโโ static/ # Static assets
โโโ docs/ # Documentation (incl. architecture.md, screenshots/)
See docs/architecture.md for a diagram of how the runtimes fit together, and CLAUDE.md for the authoritative architecture notes.
Full documentation is published to GitHub Pages:
https://starspacegroup.github.io/spacebot/ (built from docs/).
Highlights: Architecture ยท API ยท Integrations ยท AI Autopilot ยท Local Runner v2 ยท Superadmin Workflows ยท Observability ยท Tutorials.
- โ Discord request signature verification
- โ Same-origin checks for cookie-authenticated JSON mutations
- โ Security headers and report-only CSP for HTML responses
- โ HTTP-only secure cookies
- โ Configurable sliding session TTL
- โ Admin permission checks
- โ Environment variable secrets
- โ HTTPS via Cloudflare
See ROADMAP.md for planned features and enhancements.
See CONTRIBUTING.md for local setup, the project's hard rules (immutable migrations, Bun-only, the multi-runtime model), and how to run tests before opening a PR.
MIT







