disc-deploy-bot
A Discord slash-command bot that publishes a static site and replies with its live URL. It deploys to Cloudflare Pages, Surge.sh, and Wasmer Edge, and is built to run as a stateless HTTP service on Wasmer Edge.
/deploy provider:cloudflare file:site.zip project_name:my-portfolio
→ ✅ Deployed to Cloudflare Pages
https://my-portfolio.pages.dev
Why it works on Wasmer Edge
- No gateway / WebSocket. There is no
discord.jsclient. Discord sends signed HTTP POSTs to/interactions; the bot verifies them withdiscord-interactions'verifyKey(). - No shell subprocesses. No
wranglerorsurgebinaries. Every provider is called through its documented REST API withfetch(), and Wasmer deployments use@wasmer/sdk. - Deferred responses. Deployments take longer than Discord's 3-second limit. The bot immediately answers
type: 5(DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE), uploads in the background, then edits the original message viaPATCH /webhooks/{application_id}/{token}/messages/@original. - Everything in memory. Attachments are downloaded with
fetch(), ZIPs are expanded with JSZip, and Surge's tarball is created in memory. Nothing is written to disk, so read-only sandboxes are fine. - One small HTTP server.
src/index.jsuses Node's built-inhttpmodule, listens onPORT, and exposesPOST /interactionsplusGET /healthz.
Discord ──POST /interactions──▶ verify Ed25519 signature ──▶ allowlist
│
├─ type 5 (deferred) ──▶ Discord
│
└─ background: download ─▶ unzip ─▶ provider REST API
│
PATCH @original ◀── live URL / error ◀────────────┘
Requirements
- Node.js 20+ (Node 24 recommended; the Wasmer provider needs WebAssembly support).
- A Discord application with a bot token.
- Credentials for at least one provider.
- For Wasmer Edge: the Wasmer CLI.
1. Create the Discord application
- Open https://discord.com/developers/applications → New Application.
- General Information: copy Application ID and Public Key.
- Bot: reset and copy the Bot Token. No privileged intents are required.
- OAuth2 → URL Generator: select scopes
botandapplications.commands, then the Send Messages permission. Open the generated URL to invite the bot. - Leave Interactions Endpoint URL empty until the bot is reachable over HTTPS.
Discord requires the interaction endpoint to be public HTTPS with a valid certificate. Localhost only works through a tunnel such as
cloudflaredorngrok.
2. Configure
npm install
cp .env.example .env
Edit .env. ALLOWED_USER_IDS is mandatory: it lists the Discord user IDs allowed to deploy.
ALLOWED_USER_IDS=123456789012345678
It is comma-separated. If it is empty, every /deploy is denied — this is intentional, so a misconfigured bot can never publish sites under your provider credentials.
Environment variables
| Variable | Required | Purpose |
|---|---|---|
DISCORD_APP_ID | Yes | Application ID; also used in the follow-up webhook URL. |
DISCORD_PUBLIC_KEY | Yes | Verifies every interaction signature. |
DISCORD_BOT_TOKEN | For npm run register | Registers slash commands. |
DISCORD_GUILD_ID | No | Register commands in one guild (instant) instead of globally. |
ALLOWED_USER_IDS | Yes | Comma-separated user IDs allowed to deploy. |
CLOUDFLARE_API_TOKEN | For Cloudflare | Needs Cloudflare Pages: Edit. |
CLOUDFLARE_ACCOUNT_ID | For Cloudflare | Account that owns the Pages projects. |
SURGE_TOKEN | For Surge | Output of surge token. |
WASMER_TOKEN | For Wasmer | Wasmer access token with app/package write access. |
WASMER_OWNER | No | Your Wasmer username; auto-detected from the token if omitted. |
SITE_SOURCE_URL | No | Live site mirrored for Surge/Wasmer deploys. Default https://abyss-cc.web.app. |
WASMER_DEPLOY_HOURS | No | UTC hour(s) that include Wasmer in an hourly run. Default 0 (once a day). |
SITE_STATE_PATH | No | /deploy-now daily-limit state file. Default ./.build/site-links-state.json. |
SITE_HOURLY_STATE_PATH | No | Persisted hourly schedule. Default ./.build/site-links-hourly.json. |
PORT | No | HTTP port. Default 3000; Wasmer Edge injects its own value. |
MAX_UPLOAD_BYTES | No | Attachment cap. Default 10 MB, hard-capped at 25 MB. |
3. Provider credentials
Cloudflare Pages
- Copy your Account ID from the Cloudflare dashboard (Workers & Pages overview, right-hand sidebar).
- Create a token at https://dash.cloudflare.com/profile/api-tokens → Create Token → Custom token.
- Permission: Account → Cloudflare Pages → Edit. Limit it to your account.
- Set
CLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_ID.
The bot creates the Pages project on first use (production_branch: main) and returns https://<project_name>.pages.dev. Uploads use the same Direct Upload flow as wrangler, including Cloudflare's BLAKE3 asset keys — plain SHA-256 hashes would make every asset 404.
Use a Direct Upload project or let the bot create one. A Pages project connected to a Git repository cannot accept direct uploads; Cloudflare rejects those deployments.
Surge.sh
npm install -g surge
surge login
surge token
Set SURGE_TOKEN. Sites are published to https://<project_name>.surge.sh using Surge's gzipped-tar deploy API. Surge subdomains are first-come, first-served: if someone else owns the name you will get a 403. Surge also rate-limits deployments per domain and per account.
Wasmer Edge
- Create a token at https://wasmer.io/settings/access-tokens.
- Set
WASMER_TOKEN;WASMER_OWNERis optional (the bot looks up the username from the token).
Each site is packaged with wasmer/static-web-server and deployed as its own Wasmer app, returning the app's *.wasmer.app URL.
4. Register the slash command
npm run register
This sends PUT /applications/{id}/commands (or /guilds/{guild_id}/commands) with:
| Option | Type | Notes |
|---|---|---|
provider | String, required | cloudflare, surge, wasmer |
file | Attachment, required | .html / .htm or .zip, max 10 MB |
project_name | String, optional | Sanitized to lowercase a-z, 0-9 and hyphens; max 48 chars |
/deploy-now takes a required provider picked from an autocomplete list (cloudflare, surge, wasmer): it deploys exactly one saved link and is capped at one deployment per link per UTC day. Run npm run register after changing the option, then wait for (or bypass with DISCORD_GUILD_ID) command propagation.
PUT replaces the application's command set. The bot registers /deploy, /deploy-now, and /deploy-hourly. Global commands can take up to an hour to appear everywhere; set DISCORD_GUILD_ID for instant guild commands while testing.
5. Run locally
npm start
In another terminal, expose port 3000:
cloudflared tunnel --url http://localhost:3000
# or: ngrok http 3000
Put the tunnel's HTTPS URL plus /interactions into Discord Developer Portal → General Information → Interactions Endpoint URL, and save. Discord immediately sends a PING; the bot answers with {"type":1}.
Then run /deploy in your server.
6. Deploy the bot to Wasmer Edge
- Edit
app.yaml:owner: your-wasmer-username name: disc-deploy-bot - Edit
wasmer.tomland replaceyour-wasmer-usernamein[package].name. - Install production dependencies (the manifest mounts
./node_modules):npm install --omit=dev - Log in and deploy:
wasmer login wasmer deploy - Copy the printed URL. It is usually
https://disc-deploy-bot-<owner>.wasmer.app(Wasmer may use<name>.wasmer.appwhen available). - In the Wasmer dashboard for the app, open Settings → Environment variables and add every value from
.env.example. Never commit.env. - In the Discord Developer Portal, set:
https://<your-app>.wasmer.app/interactions - Save (Discord sends
PING), then run/deploy.
The health endpoint is GET https://<your-app>.wasmer.app/healthz.
If the package build rejects the mounted
node_modules, deletewasmer.tomland runwasmer deployagain. Wasmer then auto-detects the Node app frompackage.json(npm start) and installs dependencies on its builder. Keepapp.yaml.
Wasmer provider limitation
The Wasmer deployer is pinned to @wasmer/sdk@0.7.1, which exposes Wasmer.createPackage() / Wasmer.deployApp(); newer 0.19 releases replaced that API with a sandbox-only one. That SDK instantiates WebAssembly inside the process. Wasmer Edge's own Node runtime is itself WebAssembly-based and may not support nested instantiation. If provider: wasmer fails on Wasmer Edge, run this bot on a regular Node host — the Cloudflare and Surge deployers work anywhere Node runs. The error message will say so; nothing crashes or silently succeeds.
How a /deploy works
- Discord POSTs the interaction; the bot verifies
X-Signature-Ed25519againstDISCORD_PUBLIC_KEYand rejects timestamps older than 5 minutes. - The user allowlist is checked. Unauthorized users get an ephemeral refusal.
- Provider, attachment type, attachment size, credentials and
project_nameare validated before deferring. - The bot replies
type: 5with the ephemeral flag, then starts the upload in the background. - The attachment is downloaded (with a second size check), expanded in memory, stripped of a single wrapper folder if present, and required to have a root
index.html. A lone.htmlupload becomesindex.html. - The chosen deployer uploads the files via
fetch()and returns a URL. - The original response is edited with the live link, or with a clear error message.
Everything is ephemeral by default. To post results publicly, remove flags: EPHEMERAL from deferredResponse() in src/interactions.js.
Owner deployment commands
/deploy-now and /deploy-hourly are restricted to the Discord server owner, not the allowlist. The bot resolves the owner with GET /guilds/{id} using DISCORD_BOT_TOKEN; DMs and non-owners are denied.
/deploy-now provider:<link>is mandatory to pick what to publish:cloudflare,surge, orwasmer. Each link accepts one deployment per UTC day; the counter lives inSITE_STATE_PATH(default./.build/site-links-state.json) and resets at 00:00 UTC. A deployment that fails hands its slot back.- Cloudflare reuses the saved asset manifest, so already-uploaded assets are not sent again. The compiled Functions bundle is attached as
_worker.bundle, so/api/*routes keep working. - Surge and Wasmer mirror
SITE_SOURCE_URL, then upload the mirrored files.
- Cloudflare reuses the saved asset manifest, so already-uploaded assets are not sent again. The compiled Functions bundle is attached as
/deploy-hourly action:startenables the hourly run,action:stopdisables it, andaction:statusshows the next run and which links it will publish. Enabling it deploys Cloudflare Pages + Surge immediately. After that, each run starts a couple of minutes before the top of the hour — the head start is sized from the previous run's duration, so the published site is live on the hour rather than a few minutes late. Wasmer joins only at the UTC hour(s) inWASMER_DEPLOY_HOURS(default0, so once a day), judged by the hour a run is aimed at, so a 23:58 start still publishes the 00:00 Wasmer release. Cloudflare Pages and Surge are published in parallel, so a run takes about as long as the slower link.
These commands do not rebuild the GitHub repository. Cloudflare publishes the build that produced the manifest; Surge and Wasmer publish the live source. After changing the site, rebuild it and refresh the manifest:
npm run site:manifest -- /path/to/the/built/dist
# Rebuild the Pages Functions bundle when functions/ changes:
(cd /path/to/the/repo && npx wrangler pages functions build --outfile /path/to/disc-bot/data/abyss-cc-functions.bundle)
/deploy-hourly is a convenience scheduler inside the bot. Its enabled flag and due time are persisted in SITE_HOURLY_STATE_PATH, so a restart no longer silently disables it, and a slot that came due while the process was down runs as a catch-up — at startup, and on the next incoming interaction for hosts that sleep between requests. Set DEPLOY_HOURLY_ON_START=true to force it on at every boot. The relevant settings are SITE_PROJECT_NAME, SITE_URL, SITE_BRANCH, SITE_MANIFEST_PATH, SITE_WORKER_BUNDLE_PATH, SITE_SOURCE_URL, SITE_SEED_PATHS_PATH, SITE_STATE_PATH, SITE_HOURLY_STATE_PATH, WASMER_DEPLOY_HOURS, and DEPLOY_HOURLY_ON_START in .env.example.
For a durable hourly deployment that does not depend on the bot process, use the GitHub Actions workflow described below.
Hourly all-provider deployment
.github/workflows/abyss-hourly.yml runs at minute 55 of every UTC hour, so the mirror-and-publish finishes as the hour turns over rather than minutes into it. Each run:
- Mirrors
https://abyss-cc.web.appinto a temporary build directory, following HTML, CSS, JS, JSON and asset references. - Deploys the complete snapshot to Cloudflare Pages and Surge every hour.
- Deploys Wasmer Edge only at 00:00 UTC by default (
WASMER_DEPLOY_HOURS=0), so Wasmer receives one release a day while Cloudflare and Surge update hourly. A 23:55 run counts as the 00:00 slot, so the daily release is live on the hour. - Refreshes
data/abyss-cc-manifest.jsonanddata/abyss-cc-seed-paths.json; the workflow commits them only when their content actually changes.
The current links are:
- Cloudflare:
https://abyss-cc-4v6.pages.dev - Surge:
https://abyss-cc.surge.sh - Wasmer:
https://abyss-cc.wasmer.app
The workflow also supports workflow_dispatch (manually run it, optionally with force_wasmer) and a repository_dispatch event named abyss-source-updated.
Required repository secrets
Add these under Settings → Secrets and variables → Actions in the repository that hosts this workflow:
| Secret | Purpose |
|---|---|
CLOUDFLARE_API_TOKEN | Pages: Edit permission |
CLOUDFLARE_ACCOUNT_ID | Cloudflare account ID |
SURGE_TOKEN | Surge access token for abyss-cc.surge.sh |
WASMER_TOKEN | Wasmer access token |
WASMER_OWNER | akilesh_him |
Trigger an immediate source deploy
GitHub only runs the hourly schedule once the workflow is pushed and enabled. Add this workflow to the source repository if you want a push to notify the deploy repository immediately instead of waiting for the next top-of-hour run:
name: Notify Abyss deploy
on:
push:
branches: [main]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.ABYSS_DISPATCH_TOKEN }}
repository: akilesh-him/disc-bot
event-type: abyss-source-updated
The token needs permission to dispatch events to the deploy repository. The source workflow should run after the source has published abyss-cc.web.app; the deploy action mirrors that live site, not a private GitHub checkout.
Security model
- Deny by default. No allowlist entries means no deployments. A listed user ID must match.
- Signature verification on every request, with a freshness window to limit replay.
- Attachment limits. Discord's declared size is checked before download, and the real byte count is checked after. Uncompressed ZIP content is capped at 40 MB and 1,000 files.
- Archive hardening. Absolute paths,
..segments, symlinks and macOS metadata are skipped; files are never written to disk. Path lengths are bounded. - Slug sanitization.
project_nameis lowercased, reduced to[a-z0-9-], collapsed, trimmed and capped at 48 characters, satisfying all three providers. - No secret logging. Provider tokens live in headers only; errors are truncated and never include credentials.
- Daily link limit.
/deploy-nowallows one manual deployment per link per UTC day; the counter is file-backed so a restart does not reset it. - Deployed sites are public. Anyone on the allowlist can publish content under your provider account. Treat the allowlist as a publishing permission.
Project layout
src/
index.js HTTP server: POST /interactions, GET /healthz
interactions.js Signature check, allowlist, deferred response, follow-up
config.js Environment loading and validation
register-commands.js Slash-command registration (npm run register)
site-deploy.js Cloudflare deployment from the saved asset manifest
site-links.js Link orchestration, daily-eligible hourly plan, scheduler
refresh-site-manifest.js Regenerates data/abyss-cc-manifest.json
lib/
owner.js Cached guild-owner authorization
daily-quota.js File-backed per-link daily deployment limit
site-mirror.js In-memory source crawl used by Surge/Wasmer deploys
archive.js In-memory ZIP/HTML extraction and safety limits
discord.js Attachment download and @original message edit
errors.js User-safe DeployError
hash.js Cloudflare BLAKE3 asset keys + MIME types
http.js Fetch timeouts and provider error parsing
slug.js project_name sanitization
tar.js Minimal in-memory ustar + gzip writer for Surge
deployers/
cloudflare.js Pages Direct Upload (manifest + BLAKE3 assets)
surge.js surge.surge.sh gzipped-tar deploys
wasmer.js @wasmer/sdk createPackage + publishPackage + deployApp
scripts/
sync-abyss.mjs Mirror abyss-cc.web.app and deploy all three providers
.github/workflows/
abyss-hourly.yml Scheduled top-of-hour deployment + source dispatch
wasmer.toml Wasmer package manifest (edgejs-quickjs)
app.yaml Wasmer Edge app configuration
data/abyss-cc-manifest.json Saved Cloudflare Pages asset manifest
data/abyss-cc-seed-paths.json Known source paths used to seed each mirror run
data/abyss-cc-functions.bundle Optional compiled Pages Functions bundle for /deploy-now
.env.example All configuration variables
Provider limits worth knowing
| Provider | Returned URL | Notes |
|---|---|---|
| Cloudflare Pages | https://<slug>.pages.dev | Project auto-created; asset keys use BLAKE3(base64 + extension). |
| Surge | https://<slug>.surge.sh | Global subdomain namespace; 30 deploys/15 min per domain, 60 per account. |
| Wasmer Edge | https://<app>.wasmer.app | One Wasmer app per site; requires the Wasmer SDK (see limitation above). |
Deployment messages can take from a few seconds to about a minute. Discord's interaction token is valid for 15 minutes; failures after that cannot be reported back to the message, but they are logged.
Troubleshooting
| Symptom | Fix |
|---|---|
401 invalid_request_signature | DISCORD_PUBLIC_KEY is wrong, or a proxy changed the raw body. Send the exact bytes to verifyKey. |
| Discord says "application did not respond" | The endpoint must answer within 3 seconds. Check the URL, TLS certificate and that the process received the request. |
/deploy is missing | Run npm run register, re-invite with the applications.commands scope, and wait for global propagation (or use DISCORD_GUILD_ID). |
Cloudflare 403 / error 8000010 | Token lacks Cloudflare Pages: Edit, or CLOUDFLARE_ACCOUNT_ID is wrong. |
| Cloudflare deploy succeeds but assets 404 | The BLAKE3 dependency (@noble/hashes) must be installed; do not replace the asset hash with SHA-256. |
Surge 403 | The *.surge.sh subdomain belongs to another account, or the token is invalid. |
| Wasmer "Could not determine the Wasmer account" | Set WASMER_OWNER to your Wasmer username. |
| Wasmer provider fails on Wasmer Edge | Nested WebAssembly is unavailable there; run the bot on a standard Node host. |
project_name rejected by Discord | Use 1–48 characters; it is sanitized to a-z0-9- before reaching any provider. |