Skip to content

A Discord bot built with SvelteKit, hosted on Cloudflare Pages+Workers. WORK IN PROGRESS, NOT YET TESTED ON DEPLOYMENT ON CLOUDFLARE

Notifications You must be signed in to change notification settings

starspacegroup/spacebot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

65 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SpaceBot ๐Ÿš€

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.

SpaceBot Dashboard

โœจ Features

๐Ÿค– Discord Bot

  • 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

๐ŸŒ Web Dashboard

  • 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

๐Ÿ” Authentication & Security

  • 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-Native

  • Cloudflare Pages โ€” Deployed on Cloudflare's global edge network
  • D1 Database โ€” SQLite-based serverless database for logs and configurations
  • Zero Cold Starts โ€” Fast response times worldwide

๐Ÿ“ธ Screenshots

๏ฟฝ Discord Login

Discord Login

Secure Discord OAuth2 authentication for accessing the admin dashboard.

๐Ÿ“Š Server Admin (Dark Mode)

Server Admin Dark

View event logs, statistics, and quick access to automations and commands.

๐Ÿ“Š Server Admin (Light Mode)

Server Admin Light

The dashboard also supports a clean light theme.

โšก Automations

Automations List

Create event-driven automations that trigger on Discord events like member joins, message creates, voice state changes, and more.

๐Ÿ› ๏ธ Automation Editor

Automation Editor

Visual interface for configuring triggers, conditions, and actions for your automations.

๐ŸŽฎ Custom Commands

Commands

Build custom slash commands with parameters and tie them to automation actions.

โœ๏ธ Command Editor

Command Editor

Design slash commands with options, parameters, and custom responses through an intuitive editor.

๐Ÿ“ Event Logs

Event Logs

Comprehensive logging of all Discord events with filtering and search.

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿš€ Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/starspacegroup/spacebot.git
    cd spacebot
  2. Install dependencies

    npm install
  3. Configure environment variables

    Copy .env.example to .env and fill in your Discord credentials:

    cp .env.example .env

    Required variables:

    Variable Description
    DISCORD_PUBLIC_KEY Found in your app's "General Information"
    DISCORD_CLIENT_ID Your application's Client ID
    DISCORD_CLIENT_SECRET Found under OAuth2 settings
    DISCORD_BOT_TOKEN Found under "Bot" settings
    ADMIN_USER_IDS Comma-separated Discord user IDs with global admin access
    LOG_LEVEL Logging verbosity: error, warn, info, debug
  4. Set up the database (local development)

    npm run db:migrate:local
  5. Run the development server

    npm run dev

    The app will be available at http://localhost:5173

  6. Start the Gateway bot (in a separate terminal)

    npm run dev:gateway

    This captures Discord events and processes automations.

Discord Bot Setup

  1. Go to Discord Developer Portal
  2. Select your application โ†’ Bot
  3. Enable Privileged Gateway Intents:
    • โœ… Presence Intent
    • โœ… Server Members Intent
    • โœ… Message Content Intent
  4. Go to OAuth2 โ†’ URL Generator
    • Scopes: bot, applications.commands
    • Permissions: Administrator (or customize as needed)
  5. Use the generated URL to invite the bot to your server

Setting up Interactions Endpoint

For production, configure Discord to send interactions to your Cloudflare Pages URL:

  1. Deploy to Cloudflare Pages (see Deployment)
  2. Go to Discord Developer Portal โ†’ Your Application โ†’ General Information
  3. Set Interactions Endpoint URL to:
    https://your-domain.pages.dev/api/discord/interactions
    

๐Ÿ“ฆ Available npm Scripts

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

๐Ÿ”„ Automations

SpaceBot's automation engine lets you create powerful event-driven workflows:

Supported Triggers

  • 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...

Available Actions

  • ๐Ÿ“จ 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

Template Variables

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.

๐ŸŽฎ Custom Commands

Create custom slash commands through the web dashboard:

  1. Navigate to Admin โ†’ Your Server โ†’ Commands
  2. Click New Command
  3. Configure:
    • Command name and description
    • Parameters (text, numbers, users, channels, roles, etc.)
    • Response message or embed
    • Optional: Tie to an automation action
  4. Click Register with Discord to sync

๐Ÿ“‹ Event Logging

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

๐ŸŒ Deployment

Deploy to Cloudflare Pages (Recommended)

  1. Push to GitHub

    git push origin main
  2. 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
  3. Add Environment Variables In Cloudflare Pages Settings โ†’ Environment Variables, add all required variables.

  4. Create D1 Database

    wrangler d1 create spacebot-logs

    Update wrangler.toml with the database ID.

  5. Run Migrations

    npm run db:migrate
  6. Deploy Future pushes to main will auto-deploy.

See DEPLOYMENT.md for detailed instructions.

๐Ÿ“ Project Structure

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

๐Ÿ”’ Security

  • โœ… Discord request signature verification
  • โœ… HTTP-only secure cookies
  • โœ… Admin permission checks
  • โœ… Environment variable secrets
  • โœ… HTTPS via Cloudflare

๐Ÿ—บ๏ธ Roadmap

See ROADMAP.md for planned features and enhancements.

๐Ÿ“„ License

MIT

๐Ÿ”— Resources

About

A Discord bot built with SvelteKit, hosted on Cloudflare Pages+Workers. WORK IN PROGRESS, NOT YET TESTED ON DEPLOYMENT ON CLOUDFLARE

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •