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
- AI Chat for Managers — Server managers can DM the bot for AI-powered assistance using Cloudflare Workers AI
- 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
- Discord OAuth2 — Secure login with Discord credentials
- Admin Access Control — Only server admins can manage their servers
- Request Signature Verification — All Discord interactions are cryptographically verified
- 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
📊 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.
✏️ Command Editor
Design slash commands with options, parameters, and custom responses through an intuitive editor.
| Layer | Technology |
|---|---|
| Framework | SvelteKit 2 (Svelte 5) |
| Runtime | Cloudflare Pages/Workers |
| Database | Cloudflare D1 (SQLite) |
| Bot Library | Discord.js 14 |
| Styling | Custom CSS with CSS Variables |
| Auth | Discord OAuth2 |
- Node.js 18+
- 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
npm 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)
npm run db:migrate:local
-
Run the development server
npm run dev
The app will be available at
http://localhost:5173 -
Start the Gateway bot (in a separate terminal)
npm 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 |
|---|---|
npm run dev |
Start SvelteKit dev server |
npm run dev:wrangler |
Run with Wrangler (Cloudflare local environment) |
npm run dev:gateway |
Start Discord gateway bot |
npm run dev:tunnel |
Start cloudflared tunnel for local development |
npm run build |
Build for production |
npm run db:migrate |
Run database migrations (production) |
npm run db:migrate:local |
Run database migrations (local) |
npm run register-commands |
Register slash commands with Discord |
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
- 🏷️ 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:
npm 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
npm run db:migrate
-
Deploy Future pushes to
mainwill auto-deploy.
See DEPLOYMENT.md for detailed instructions.
spacebot/
├── src/
│ ├── lib/
│ │ ├── automation/ # Automation engine
│ │ ├── components/ # Svelte components
│ │ ├── db/ # Database functions
│ │ │ ├── automations.js
│ │ │ ├── commands.js
│ │ │ └── logger.js
│ │ └── discord/ # Discord integration
│ │ ├── cache.js
│ │ ├── commands.js
│ │ ├── gateway.js # Gateway bot service
│ │ └── guilds.js
│ ├── routes/
│ │ ├── admin/ # Admin dashboard pages
│ │ │ ├── [serverId]/ # Per-server management
│ │ │ │ ├── automations/
│ │ │ │ ├── commands/
│ │ │ │ └── logs/
│ │ ├── api/ # API endpoints
│ │ │ ├── automations/
│ │ │ ├── commands/
│ │ │ ├── discord/
│ │ │ └── logs/
│ │ └── login/
│ └── app.html
├── migrations/ # D1 database migrations
├── scripts/ # Utility scripts
├── static/ # Static assets
└── docs/
└── screenshots/ # Documentation images
- ✅ Discord request signature verification
- ✅ HTTP-only secure cookies
- ✅ Admin permission checks
- ✅ Environment variable secrets
- ✅ HTTPS via Cloudflare
See ROADMAP.md for planned features and enhancements.
MIT






