Public
Discord moderation bot — 52 slash commands (serverless)
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

🛡️ ReSecurity

A serverless Discord moderation bot with 52 slash commands, running on Val Town. No 24/7 server needed — Discord sends each /command to an HTTP endpoint as a signed interaction, and this val responds.

Why slash commands and not a "gateway" bot? Val Town is serverless — it can't hold an always-on WebSocket connection. Discord's HTTP Interactions model is the supported way to build a bot here, and it covers every moderation action below.

Architecture

Rendering mermaid diagram...
FileRole
main.tsHTTP endpoint: verifies signature, routes interactions
register.tsRun once to register commands with Discord
lib/verify.tsEd25519 signature verification (tweetnacl)
lib/discord.tsDiscord REST API wrapper (ban/kick/timeout/…)
lib/respond.tsInteraction response & embed helpers
lib/db.tsSQLite storage for warnings, cases, notes
commands/*The 52 command handlers, grouped by area

Commands (52)

  • Members: ban unban kick timeout untimeout mute unmute softban hardban warn warnings warnpoints delwarn clearwarns modlogs case report note notes nick resetnick dehoist whois userid avatar voicekick
  • Channels: purge clean slowmode slowmodeoff lock unlock lockdown freeze settopic rename nsfw
  • Roles: addrole removerole roles roleinfo
  • Server / utility: serverinfo membercount banlist say embed announce poll ping invite help about

Every action command checks the invoker's Discord permissions (Ban/Kick/Moderate/Manage…) before running.

Setup

1. Create the Discord application

Go to https://discord.com/developers/applicationsNew Application. Under Bot, create a bot and copy its token. Under General Information, copy the Application ID and Public Key.

2. Set environment variables

This val needs four env vars (the 4th is optional):

DISCORD_PUBLIC_KEY   # General Information → Public Key
DISCORD_BOT_TOKEN    # Bot → Token
DISCORD_APP_ID       # General Information → Application ID
DISCORD_GUILD_ID     # (optional) a test server ID for instant command updates

👉 Add DISCORD_PUBLIC_KEY here: https://www.val.town/x/dedewahyu/ReSecurity/environment-variables?key=DISCORD_PUBLIC_KEY 👉 Add DISCORD_BOT_TOKEN here: https://www.val.town/x/dedewahyu/ReSecurity/environment-variables?key=DISCORD_BOT_TOKEN 👉 Add DISCORD_APP_ID here: https://www.val.town/x/dedewahyu/ReSecurity/environment-variables?key=DISCORD_APP_ID 👉 Add DISCORD_GUILD_ID here: https://www.val.town/x/dedewahyu/ReSecurity/environment-variables?key=DISCORD_GUILD_ID

3. Set the Interactions Endpoint URL

In General Information, set Interactions Endpoint URL to this val's main.ts HTTP endpoint. Discord will send a PING to verify it — the bot answers with a PONG automatically. (This only succeeds once DISCORD_PUBLIC_KEY is set.)

4. Register the commands

Run register.ts (the Run button, or the val's run UI). With DISCORD_GUILD_ID set, commands appear instantly in that server; without it they register globally (can take up to ~1 hour to propagate).

5. Invite the bot

In OAuth2 → URL Generator, select the bot and applications.commands scopes plus the moderation permissions you want (Ban Members, Kick Members, Moderate Members, Manage Channels, Manage Roles, Manage Messages), open the generated URL, and add the bot to your server. Make sure the bot's role is above the members it needs to moderate.

Notes & limits

  • purge can only bulk-delete messages younger than 14 days (Discord limit).
  • timeout/mute max duration is 28 days (Discord limit).
  • The bot's role must be higher than its targets, or actions return 403.