Claude Code Discord Integration
Use Claude Code with Discord to build bots, register slash commands, send webhooks, and ship reliable discord.js features faster with AI-assisted development.
By David Iya - Updated 2026-08-27
You want a Discord bot that actually works, but discord.js has too many moving parts: you register slash commands that never appear, hit missing-intent errors, blow past the three second interaction window, and fight rate limits, so a simple bot takes an evening instead of an hour.
Before you start
- Claude Code available in the development environment where you will build the bot, either the desktop app or the CLI.
- A Discord account with permission to add a bot to at least one server you control.
- A registered application and bot in the Discord Developer Portal, with the bot token copied and stored securely.
- Node.js 18 or newer and a package manager such as npm installed locally.
- The gateway intents your bot needs enabled in the Developer Portal, including any privileged intents like Message Content or Server Members.
What it unlocks
Faster Bot Scaffolding
Describe the bot you want and have Claude Code generate the client setup, login flow, intents, and folder structure so you start from a working skeleton instead of a blank file.
Correct Slash Command Registration
Generate the deploy-commands script and command builders so your application commands register with the right names, options, and scopes and actually appear in Discord.
Reliable Event Handling
Wire up gateway event listeners for messages, interactions, guild joins, and member updates with the correct intents, so the bot responds to the events you care about.
Rich Embeds and Components
Build embeds, buttons, select menus, and modals that stay within Discord's field and character limits, so interactive messages render correctly the first time.
Webhook Notifications
Generate webhook senders that post formatted alerts and embeds into a channel from CI, monitoring, or other systems without running a full bot process.
Moderation Automation
Draft moderation logic for spam filtering, keyword actions, role gating, and audit logging so repetitive community management runs on rules instead of manual clicks.
Faster Debugging of Discord Errors
Paste the exact error Discord returns and have Claude Code explain whether it is an intent, scope, permission, or rate-limit problem and how to fix it.
Safer Permission and Intent Choices
Get a clear explanation of which gateway intents and OAuth2 scopes a feature actually needs, so you request least privilege instead of enabling everything.
Production-Ready Deployment
Generate hosting configuration, environment variable handling, and reconnect logic so the bot keeps a healthy gateway connection once it leaves your machine.
Higher Developer Productivity
Offload the repetitive discord.js boilerplate, command wiring, and component building so you spend your time on the behavior that makes the bot valuable.
How to connect Discord
Create the Discord application and bot
In the Discord Developer Portal, create a new application, add a bot user, and copy the bot token. Enable the privileged gateway intents your bot needs, such as Message Content or Server Members, only if a feature requires them.
# Developer Portal: https://discord.com/developers/applicationsScaffold the project
Create a project folder, initialize npm, and install discord.js. Ask Claude Code to scaffold the client with the intents your bot needs and a basic login flow.
npm init -y && npm install discord.jsStore the token securely
Put the bot token, application id, and any guild id into a .env file that is listed in .gitignore. Never paste the token into a prompt or commit it to the repository.
echo "DISCORD_TOKEN=your-token-here" >> .envRegister slash commands
Have Claude Code generate command builders and a deploy-commands script, then run it to register your slash commands. Guild-scoped commands appear instantly, while global commands can take up to an hour to propagate.
node deploy-commands.jsRun and test the bot
Start the bot, invite it to a test server using an OAuth2 URL with the bot and applications.commands scopes, and confirm your slash commands appear and respond. Check the console for any missing-intent or permission errors.
Build and Ship a Slash-Command Bot
Describe the bot
Tell Claude Code what the bot should do, for example a /ping and /weather command, and which server it runs in.
Scaffold the client
Ask Claude Code to generate the discord.js client with the required gateway intents and a login flow that reads the token from the environment.
Build the commands
Have Claude Code write the slash command builders and their handlers, keeping each reply inside the three second interaction window or deferring when a call is slow.
Register the commands
Generate a deploy-commands script and register the commands to a test guild so they appear instantly for testing.
Test in the server
Invite the bot with the bot and applications.commands scopes, run each command, and confirm the responses and embeds render correctly.
Deploy
Ask Claude Code to add hosting configuration, environment variables, and reconnect handling, then deploy the bot so it runs continuously.
What people build with it
Build a Bot From Scratch
Scaffold a new discord.js bot with the client, intents, login flow, and command handler so you have a running bot in minutes.
Register Slash Commands
Generate command builders and a deploy-commands script that registers global or guild slash commands with options, subcommands, and permissions.
Handle Gateway Events
Wire event listeners for messageCreate, interactionCreate, guildMemberAdd, and other events with the correct intents enabled.
Design Embeds
Build rich embed messages with titles, fields, colors, thumbnails, and footers that stay inside Discord's embed limits.
Add Buttons and Select Menus
Create message components such as buttons, select menus, and modals, then wire the interaction handlers that respond to them.
Send Webhook Alerts
Post deploy notifications, monitoring alerts, or scheduled summaries into a channel through a Discord webhook without a persistent bot.
Automate Moderation
Build spam filters, keyword actions, slow-mode toggles, and audit logging so community rules are enforced automatically.
Role Management
Add reaction-role, button-role, or command-driven role assignment so members self-select roles under rules you define.
Welcome and Onboarding Flows
Greet new members, send onboarding embeds, and gate access behind an agreement or verification step.
Ticket and Support Systems
Create a button-driven support flow that opens private channels or threads and notifies the moderation team.
Scheduled Messages and Reminders
Set up cron-style tasks that post recurring announcements, reminders, or digests into chosen channels.
External API Integrations
Have a slash command call an external API, format the result into an embed, and reply within the interaction window.
Analytics and Logging
Log message events, command usage, and member changes to a database or channel for community insight.
Deploy and Host the Bot
Generate hosting configuration and process management so the bot runs continuously and reconnects after a gateway drop.
Debug a Broken Bot
Diagnose why commands are not registering, events are not firing, or interactions are timing out based on the errors Discord returns.
Commands & configuration
Install discord.js
npm install discord.jsAdds the core library used to build the bot client, commands, and components.
Store the bot token
echo "DISCORD_TOKEN=your-token-here" >> .envKeep the token in .env and add .env to .gitignore so it is never committed.
Register slash commands
node deploy-commands.jsRuns the script that pushes your application commands to Discord. Guild commands appear instantly; global commands can take up to an hour.
Slash command registration snippet
const { REST, Routes } = require('discord.js'); const rest = new REST().setToken(process.env.DISCORD_TOKEN); await rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID), { body: commands });The core of deploy-commands.js. Use applicationCommands for global registration instead of applicationGuildCommands.
Start the bot
node index.jsLaunches the bot and opens the gateway connection. Watch the console for missing-intent or login errors.
Run the bot with a process manager
npx pm2 start index.js --name discord-botKeeps the bot running in production and restarts it if the process exits.
Prompts to steal
Scaffold a Discord bot
Scaffold a new discord.js bot for me. Set up the client with the gateway intents needed for slash commands and message events, load the token from a DISCORD_TOKEN environment variable, add a ready event that logs when the bot connects, and give me a clean folder structure for commands and events.
Add a slash command
Add a slash command called /ping that replies with the bot's latency. Write the command builder, the handler, and update the deploy-commands script so it registers correctly. Make sure the reply stays inside the three second interaction window.
Generate the deploy-commands script
Generate a deploy-commands.js script that registers all slash commands in my commands folder. Support both guild-scoped registration for testing and global registration for production, reading the application id, guild id, and token from environment variables.
Set the correct gateway intents
Here is my bot code. Tell me exactly which gateway intents this bot needs based on the events it listens to, flag any privileged intents like MessageContent or GuildMembers that I must enable in the Developer Portal, and update the client to request only those intents.
Handle interaction events
Set up an interactionCreate handler that routes chat input commands, button presses, and select menu choices to the right handler functions. Add error handling so a failing interaction replies with an ephemeral error message instead of leaving the user with a failed interaction.
Build a rich embed
Build a rich embed for an announcement message with a title, description, three fields, a color, a thumbnail, and a footer with a timestamp. Keep every field inside Discord's embed limits and show me how to send it from a slash command.
Add buttons to a message
Add two buttons to a message, one primary and one danger style, and write the button interaction handler that responds when each is clicked. Make the response ephemeral and explain how to keep the button custom ids unique.
Create a select menu
Create a string select menu that lets a user pick a role from a list, then write the handler that assigns the chosen role. Explain which permissions and intents the bot needs to manage roles.
Send a webhook notification
Write a small Node script that sends a formatted embed to a Discord channel through a webhook URL. It should take a title and message as input and post a deploy notification. Do not include the webhook URL in the code, read it from an environment variable.
Build a welcome flow
Add a guildMemberAdd handler that greets new members with an embed in a welcome channel and assigns them a default role. Tell me which privileged intents I need to enable for this to work.
Automate moderation
Build a simple moderation feature that deletes messages containing a configurable list of banned words, warns the user with an ephemeral reply, and logs the action to a moderation channel. Keep the banned-word list in a config file, not hardcoded.
Add reaction roles
Implement reaction roles: when a user reacts to a specific message with a given emoji, assign a mapped role, and remove it when they remove the reaction. Explain the intents and permissions required and how to store the message-to-role mapping.
Create a ticket system
Build a button-driven support ticket system. A button in a support channel opens a private thread for the user, pings the moderation role, and posts a close button. Write the handlers and explain the permissions the bot needs to create and manage threads.
Defer a slow interaction
This slash command calls an external API that sometimes takes longer than three seconds and the interaction fails. Refactor it to defer the reply immediately and then edit the reply once the API responds, so the interaction never times out.
Debug commands not appearing
My slash commands are not showing up in Discord even though the bot is online. Walk me through the likely causes, including guild versus global registration, missing applications.commands scope in the invite, and errors in the deploy-commands run, and help me fix it.
Fix a missing intents error
My bot throws an error about a disallowed or missing intent when it starts, or an event never fires. Identify which intent is missing based on my event listeners, explain whether it is privileged, and update both my client options and the Developer Portal settings I need to change.
Handle rate limits
My bot is hitting 429 rate-limit errors when it sends many messages in a loop. Explain how Discord rate limits work, refactor the code to respect them with proper spacing or batching, and add handling that waits for the retry-after value instead of retrying immediately.
Deploy the bot to production
Help me deploy this bot to a host so it runs continuously. Add environment variable handling, a process manager or hosting config, graceful shutdown, and gateway reconnect handling so it recovers from disconnects. Do not put the token anywhere it could be committed.
Add scheduled messages
Add a scheduled task that posts a daily summary embed to a specific channel at a set time. Use a cron-style scheduler, read the channel id from configuration, and make the schedule easy to change without editing the core logic.
Review the bot for security and reliability
Review my Discord bot for security and reliability problems: exposed tokens, over-broad intents or permissions, unhandled interaction errors, missing rate-limit handling, and unsafe user input passed to other systems. For each finding explain the risk and the fix, and do not print any secret values.
Recommended MCP servers
A widely used Discord MCP server built on discord.js that lets Claude Code send and read messages, manage channels, work with forum posts, and add reactions through MCP tools. Supports stdio and streamable HTTP transports and ships as an npm package and Docker image.
A lightweight, multi-guild Discord MCP server with 95 plus tools that explicitly supports Claude Code, letting you manage channels, roles, members, and messages across servers from inside your Claude Code session.
Skills worth having
Generate a working discord.js bot skeleton with the client, intents, login flow, and command handler structure.
Build application command definitions with options, subcommands, and permissions, plus the deploy-commands script to register them.
Wire gateway event listeners with the correct intents so the bot responds to messages, interactions, and member events.
Create embeds, buttons, select menus, and modals that respect Discord's field and character limits.
Produce webhook senders that post formatted alerts and embeds into a channel from external systems.
Draft spam filters, keyword actions, role gating, and audit logging for automated community moderation.
Set up hosting, environment variables, process management, and reconnect handling for a production bot.
Diagnose intent, scope, permission, rate-limit, and interaction-timeout errors from the messages Discord returns.
Troubleshooting
Keep it safe
- Never commit the bot token. Keep it in a .env file listed in .gitignore, and if a token is ever exposed, reset it immediately in the Developer Portal.
- Never paste the token into a prompt. Reference secrets by environment variable name instead of putting the raw token or webhook URL into prompts or public tools.
- Request least-privilege intents. Enable only the gateway intents a feature needs, and avoid privileged intents like Message Content unless a workflow truly requires them.
- Grant minimal bot permissions. Give the bot only the server and channel permissions its features use rather than Administrator, and keep its role position no higher than needed.
- Validate user input. Treat command options and message content as untrusted, and never pass raw user input directly into shell commands, database queries, or other systems.
- Keep a human in the loop on destructive actions. Require confirmation for bans, mass deletes, and role changes, and log moderation actions so they can be reviewed.
Discord + Claude Code: FAQ
What is the Claude Code Discord integration?
It is a workflow that lets you build and maintain Discord bots with Claude Code. Claude Code can scaffold a discord.js bot, register slash commands, wire event handlers, build embeds and buttons, send webhooks, and debug the errors Discord returns. Your Discord application stays the source of truth while Claude Code writes and explains the code around it.
How do I build a Discord bot with Claude Code?
Create an application and bot in the Discord Developer Portal, copy the token, and store it in a .env file. Then ask Claude Code to scaffold a discord.js client with the intents you need, generate your slash commands and a deploy-commands script, and wire the handlers. Run the deploy script, invite the bot with the bot and applications.commands scopes, and test it in your server.
Do I need a Discord MCP server?
No, you can build bots with Claude Code using just discord.js. A Discord MCP server is optional and useful when you want Claude Code to read and act on a live server during development, such as sending messages, managing channels, or inspecting roles from inside your session. Servers like mcp-discord or @pasympa/discord-mcp expose those actions as MCP tools.
Why are my slash commands not appearing?
The most common causes are that the deploy-commands script was never run, the commands were registered globally and have not propagated yet, or the bot was invited without the applications.commands scope. Register to a test guild for instant updates while developing, check the deploy script output for errors, and re-invite the bot with the correct scopes.
How do I fix a missing intents error?
A missing or disallowed intents error means your client is missing a gateway intent that an event needs, or a privileged intent is not enabled in the Developer Portal. Identify which intent each event listener requires, add it to your client options, and enable any privileged intents such as Message Content or Server Members in the portal, then restart the bot.
Why does my interaction fail after three seconds?
Discord requires you to acknowledge an interaction within three seconds. If your handler does slow work before replying, the interaction times out. Call deferReply immediately at the start of a slow handler, do the work, then use editReply to send the final response so the interaction never fails.
Can Claude Code help with webhooks?
Yes. Claude Code can generate a script that posts formatted messages and embeds to a channel through a Discord webhook, which is a lightweight way to send deploy alerts, monitoring notifications, or scheduled summaries without running a full bot. Store the webhook URL in an environment variable rather than in code.
Can Claude Code automate moderation?
Yes. Claude Code can build moderation features such as spam and keyword filters, role gating, welcome flows, and audit logging. Keep configurable lists in a config file, require confirmation for destructive actions like bans or mass deletes, and log moderation actions so a human can review them.
Go deeper
More integrations
Build Better Discord Bots With Claude Code
Join Claude Code Club to access practical tutorials, prompts, skills, MCP guides, workflows, templates, and real builds designed to help you get more from Claude Code.
Related: what is Claude Code, glossary, and use cases.
