Skip to content
Misar.io

How to Create a Discord Bot with AI in 2026 (Step-by-Step Guide)

All articles
Guide

How to Create a Discord Bot with AI in 2026 (Step-by-Step Guide)

Build and deploy a Discord bot with slash commands, AI responses, and persistent data — from zero to live server in under 2 hours.

Misar Team·Aug 28, 2025·4 min read
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.

discord-botdiscordjsai-codingbot-developmentnodejs
Enjoyed this article? Share it with others.

More to Read

View all posts
Guide

How to Train an AI Chatbot on Website Content Safely

Website content is one of the richest sources of information your business has. Every help article, FAQ, service description, and policy page is a direct line to your customers’ most pressing questions—yet most of this d

9 min read
Guide

E-commerce AI Assistants: Use Cases That Actually Drive Revenue

E-commerce is no longer just about transactions—it’s about personalized experiences, instant support, and frictionless journeys. Today’s shoppers expect more than just a website; they want a concierge that understands th

11 min read
Guide

What a Healthcare AI Assistant Needs Before Launch

Healthcare AI isn’t just about algorithms—it’s about trust. Patients, clinicians, and regulators all need to believe that your AI assistant will do more than talk; it will listen, remember, and act responsibly when it ma

12 min read
Guide

Website AI Chat Widgets: What Converts Better Than Generic Bots

Website AI chat widgets have become a staple for SaaS companies looking to engage visitors, answer questions, and drive conversions. Yet, most chat widgets still rely on generic, rule-based bots that frustrate users with

11 min read

Explore Misar AI Products

From AI-powered blogging to privacy-first email and developer tools — see how Misar AI can power your next project.

Stay in the loop

Follow our latest insights on AI, development, and product updates.

Get Updates