How to vibe code a Discord bot

Discord bots are a perfect agent project: the API is superbly documented (discord.js), the feedback loop is 'type /command in your server', and a bot your community actually uses is the most public proof of vibe coding there is.

Two decisions matter before you prompt: what the bot does (start with three slash commands, not thirty) and where it lives (bots need a host that stays awake — that's the only real gotcha).

Tool: Claude Code — bots are long-running Node processes with real config, and its shell access makes register-commands/run/test loops smooth. Time: one sitting for a working bot. The free deep-dive: Agentic AI Engineering.

The steps
  1. 1

    Create the Discord application

    Discord Developer Portal → New Application → Bot → copy the token (treat it like a password — env var, never in code). Invite it to your server with only the permissions it needs.

  2. 2

    Scaffold with three slash commands

    Ask for discord.js + TypeScript with a clean command-handler structure and three commands that matter to your server. Slash commands need registering — have the agent write the register script and explain guild vs global registration (guild updates instantly; use it while developing).

  3. 3

    Test live in your server

    Run it locally; the bot comes online; type the commands. Iterate exactly like any vibe project: paste error logs, describe wrong behavior, rerun.

  4. 4

    Give it a memory or a brain

    A small database (SQLite locally, Postgres hosted) unlocks leaderboards, reminders, per-user stats. An LLM API unlocks the fun tier: summarize the last 50 messages, answer questions in your community's voice, moderate tone. This is agentic-AI thinking in miniature — our Course 04 is the deep end.

  5. 5

    Host it somewhere that stays awake

    Bots hold a websocket open, so serverless won't do: use Railway, Fly.io, or a $5 VPS. Ask the agent for a Dockerfile + deploy steps for your pick, plus auto-restart on crash. When it survives your laptop closing, it's real.

Starter prompt — paste into your agent
Build a Discord bot with discord.js and TypeScript. Commands (slash commands, clean command-handler folder structure): [three commands and what they do]. Include: a register-commands script (guild-scoped for dev, with comments on switching to global), token and IDs via .env (never committed), graceful error replies, and a README covering Developer-Portal setup, invite-link scopes, and local run. Then add a Dockerfile and deploy instructions for Railway. Wait for my feedback after the three commands work locally.
Frequently asked questions

Why does my bot go offline when I close my laptop?

Bots are persistent processes, not websites — they need a host that keeps them running (Railway, Fly.io, a small VPS). This is the #1 beginner surprise. Deploy once and it stays online; the agent writes the deploy config in one prompt.

Can the bot use ChatGPT/Claude to answer questions?

Yes — wire an LLM API key (env var) and add a command or mention-handler that sends recent channel context to the model. Set a system prompt for tone, cap the context you send, and rate-limit per user to control costs. It's ~50 lines and our Agentic AI course explains every piece.