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 /ask command, 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_TOKEN is set. Bot auto-reconnects on restart.
- Invite to server. Use OAuth2 URL Generator → select bot + applications.commands scopes → minimum permissions → paste URL in browser.
Common Mistakes
- Committing tokens: Add .env to .gitignore before 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
FAQs
Q: Does my bot need to be verified?
Only at 100+ servers. Below that, no verification required.
Q: Can the bot respond to DMs?
Yes — listen for Events.MessageCreate with channel.type === ChannelType.DM.
Q: How do I add buttons and modals?
Use ActionRowBuilder with ButtonBuilder and ModalBuilder — ask AI for the exact discord.js v14 syntax.
Q: What's the best free host?
Railway free tier or a $5/mo Hetzner VPS for unlimited uptime.
Q: Can I store user data?
Yes — use Supabase (self-hosted free), SQLite, or Redis. Keep Discord IDs as your primary key.
Q: How do I test without spamming my real server?
Create a test server and use guild-scoped commands for instant updates.
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.