Discord Shop & Community Bot

Modular, production-ready Discord bot for a shop / marketplace / community. Built in phases.

Status — Phase 2 (Shop + Orders + Customers) ✅

  • Ed25519 interaction signature verification (Web Crypto, no secrets in code)
  • PING handling, slash-command registry + dispatcher, unified premium embeds
  • Shop/shop browse, /shop view, /shop buy, /shop product-add
  • Orders/order view (receipt), /order history, /order update, statuses
  • Customers — auto-profiles on first order, /customer view|history|note
  • Persistence — SQLite (std/sqlite): customers, products, orders
  • Integration — buying updates customer stats/spending/last-purchase + order notifications
  • Security: server-side permission checks, ephemeral responses, parameterized SQL
  • Tickets, Giveaways, Moderation, Promotions, etc. (next phases)

Architecture

main.ts             HTTP endpoint — verify, PING, route commands/components/modals
lib/verify.ts       Ed25519 signature verification + freshness check
lib/commands.ts     slash-command registry + permission helper + dispatcher
lib/components.ts   button / select / modal routing (custom_id tags)
lib/embeds.ts       one shared premium embed/UI builder
lib/config.ts       persistent config (std/blob)
lib/db.ts           SQLite schema + repositories (customers/products/orders)
lib/shop.ts         product management + browsing
lib/orders.ts       buy flow, receipts, order updates
lib/customers.ts    customer profiles & history

Commands

CommandAccessPurpose
/pingallhealth check
/setupallrun setup + config summary
/panelstaff/ownercontrol panel
/shop browseallcatalogue
/shop view <product>allproduct detail
/shop buy <product> [qty]allplace an order
/shop product-add …staffadd a product
/order view <order>ownerreceipt
/order history [customer]allorder history
/order update <order> <status>staffchange order status
/customer view [customer]allcustomer profile
/customer history <customer>stafffull history
/customer note <customer> <note>staffstaff note
/moderation warn <user>staffissue a warning (case)
/moderation ban <user>staffban + case
/moderation kick <user>staffkick + case
/moderation timeout <user> [min]stafftimeout + case
/moderation cases [user]staffmoderation case log
/ticket new [category] [subject]allopen a ticket
/ticket close [id]allclose your ticket
/giveaway create <prize> [min] [winners]staffstart a giveaway
/giveaway enter <id>allenter a giveaway
/giveaway end/reroll <id>staffend/reroll a giveaway
/suggestion submit <text>allsubmit a suggestion
/suggestion vote <id> [up/down]allvote on a suggestion
/poll create <question> <options>allcreate a poll
/poll vote <id> <letter>allvote on a poll
/review add <order> [rating] [text]allreview a completed order
/promotion create/status …staffpromotions
/autorole add/remove/list/enable/disable/test/settingsstaffautorole system

Autorole note: applying roles on raw member-join needs a persistent Discord gateway connection, which Val Town's serverless interaction endpoints don't provide. /autorole test applies + validates on demand; applyAutoroles(guildId, userId) in lib/autorole.ts is the hook a gateway worker would call on join.

Next phases (not yet built)

Tickets (+ transcripts + ratings) · Giveaways · Welcome/Leave · Automod/Anti-raid/Anti-nuke · Applications · Reports · Reviews · Trading/Middleman · Promotions · Roles/VIP · Suggestions/Polls · Custom commands · Scheduled announcements · Logging · Analytics · Owner tools · Blacklist · Backup/Restore · Workflow engine · Web dashboard

Setup

  1. Env vars on the val:
    • DISCORD_PUBLIC_KEY, DISCORD_BOT_TOKEN, DISCORD_APP_ID, DISCORD_OWNER_ID
  2. Interactions Endpoint URL in the dev portal → Try the app
  3. Invite the bot with Administrator perms (slash commands auto-register on deploy).

🔴 Rotate your bot token — it was exposed in chat earlier. Secrets live only in env vars.