Table of Contents
Quick Answer
Use discord.js v14 with Claude Code to scaffold a bot, register slash commands via the Discord Developer Portal, and deploy to a free-tier Railway or self-hosted VPS. AI handles event handlers, intent configuration, and command routing.
- Time to first deploy: 90 minutes
- Cost: $0 (free tier hosting)
- Requirements: Discord account, Node.js 20+
What You'll Need
- Discord account with server admin rights
- Node.js 20+ and pnpm
- Cursor or Claude Code
- A VPS, Railway account, or Fly.io (free tier works)
Steps
- Create the bot application. Go to Discord Developer Portal, click "New Application", name it, then under "Bot" copy the token (keep secret).
- Set intents. In the Bot tab, enable required Privileged Intents (Message Content, Server Members) only if your bot needs them.
- Scaffold with AI. Prompt: "Create a discord.js v14 bot with slash commands (/ping, /ask), using dotenv for the token and a commands folder pattern." Install:
pnpm add discord.js dotenv. - Register slash commands. Create
deploy-commands.js. Ask AI: "Generate a script that registers slash commands globally via Discord REST API using CLIENT_ID and GUILD_ID from env." - Add AI responses. For the
/askcommand, route to an AI provider through your backend (never hardcode API keys). Stream responses if over 2000 characters — split into multiple messages. - Deploy. Push to a VPS or Railway. Ensure
process.env.DISCORD_TOKENis set. Bot auto-reconnects on restart. - Invite to server. Use OAuth2 URL Generator → select
bot+applications.commandsscopes → minimum permissions → paste URL in browser.
Common Mistakes
- Committing tokens: Add
.envto.gitignorebefore first commit. If leaked, regenerate immediately. - Enabling all intents: Slows approval and triggers verification when your bot hits 100 servers.
- Not handling rate limits: discord.js handles most automatically, but bulk DMs will get you banned.
- Forgetting global vs guild commands: Global takes up to 1 hour to propagate; guild-scoped is instant for dev.
Top Tools
| Tool | Best For | Price |
|---|---|---|
| discord.js | Node.js library | Free |
| Discord.py | Python alternative | Free |
| Railway | Free-tier hosting | $0-5/mo |
| Fly.io | Edge deployment | Free tier |
| PM2 | Process manager on VPS | Free |
Conclusion
Discord bots are the fastest feedback loop in bot dev. Scaffold with AI, deploy to free hosting, and watch your command usage metrics. Start simple — one useful command beats ten half-working ones.
