intermediate15 minutes10 min read

How to Create an AI Discord Bot

Step-by-step guide to creating a Discord bot powered by your OpenClaw AI agent for community engagement, moderation, and support.

How to Create an AI Discord Bot

Discord is home to communities of all sizes — from gaming groups to developer teams to business communities. An AI-powered Discord bot can transform your server by providing instant answers, engaging community members, helping with moderation, and automating common tasks.

In this guide, you will create a Discord bot from scratch, connect it to your OpenClaw agent on EZClaws, and configure it to serve your community. By the end, you will have a fully functional AI bot in your Discord server that responds to messages, answers questions, and assists your members.

Prerequisites

Before starting, make sure you have:

  • A running OpenClaw agent on EZClaws — Deploy one with our deployment guide.
  • A Discord account with a server — You need to have "Manage Server" permissions on the server where you want to add the bot.
  • An active EZClaws subscription — Discord bots in active communities can generate significant usage. See plan options at /pricing.
  • Access to the Discord Developer Portal — Available at discord.com/developers.

Step 1: Create a Discord Application

Navigate to the Discord Developer Portal and click New Application.

Give your application a descriptive name like "AI Assistant" or "Community Helper." This name will appear in the "About Me" section of the bot's profile, though the bot's display name can be set separately.

Click Create. You will be taken to the application's settings page.

Configure General Information

On the General Information page:

  • Name — Your application name (can be changed later).
  • Description — A brief description of what the bot does. This is shown to users during the authorization process.
  • App Icon — Upload an image for your bot's avatar (recommended: 512x512 pixels).

Step 2: Create the Bot User

In the left sidebar, click Bot. Then click Add Bot and confirm.

On the bot settings page, configure the following:

Bot Username

Set the bot's display name. This is what server members will see in the member list and messages.

Token

Click Reset Token to generate a new bot token. Copy it immediately — you will not be able to see it again.

# Your bot token will look like:
MTEyMzQ1Njc4OTAxMjM0NTY3.XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Store this token securely. Anyone with this token can control your bot.

Privileged Gateway Intents

Enable the following intents:

  • Message Content Intent — Required for the bot to read message content. Without this, the bot can only see messages where it is mentioned.
  • Server Members Intent — Optional. Enable if you want the bot to access the member list.
  • Presence Intent — Optional. Enable if the bot needs to see member online status.
Important: Message Content Intent is required for the bot to read
and respond to messages in channels. Without it, the bot can only
respond to slash commands and direct mentions.

Step 3: Generate an Invite Link

To add the bot to your server, you need an invite link with the correct permissions.

In the left sidebar, click OAuth2 > URL Generator.

Select the following scopes:

bot                    — Required for a bot user
applications.commands  — Required for slash commands

Under Bot Permissions, select:

Send Messages          — Send messages in channels
Send Messages in Threads — Respond in threads
Read Message History   — Access previous messages for context
Add Reactions          — React to messages
Embed Links            — Send rich embeds
Attach Files           — Share files
Use Slash Commands     — Register and respond to slash commands
Manage Messages        — Edit and delete messages (for moderation)
View Channels          — See channels and their messages

Copy the generated URL at the bottom of the page. Open it in your browser and select the server where you want to install the bot. Click Authorize.

Your bot is now in your server, but it is offline until you connect it to your EZClaws agent.

Step 4: Connect to Your EZClaws Agent

Navigate to the EZClaws skills marketplace at /app/marketplace and install the Discord integration skill on your agent.

Configure the Skill

Enter the following credentials from your Discord Developer Portal:

Bot Token — The token you copied in Step 2.

Bot Token: MTEyMzQ1Njc4OTAxMjM0NTY3.XXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Application ID — Found on the General Information page of your Discord application.

Application ID: 1123456789012345678

Additional Settings:

  • Response Trigger — Choose how the bot should be activated:
    • mention — Only responds when @mentioned (recommended for active channels)
    • prefix — Responds to messages starting with a prefix like !ask
    • all — Responds to every message in channels where it is present (use cautiously)
  • Response Style — Thread replies vs. channel replies.
  • DM Support — Enable or disable direct message interactions.

Save the configuration. Within 30 seconds, your bot should appear online in your Discord server.

Step 5: Configure Bot Behavior

Customize the bot's behavior through your agent's system prompt:

You are an AI assistant for the [Community Name] Discord server.
Your role is to help community members with questions and discussions.

DISCORD-SPECIFIC BEHAVIOR:
- Keep responses under 2000 characters (Discord's message limit)
- For longer responses, split into multiple messages
- Use Discord markdown: **bold**, *italic*, `code`, ```code blocks```
- Use > for blockquotes when referencing other messages
- React with appropriate emoji to acknowledge messages
- When mentioned in a busy channel, keep responses concise

TRIGGER RULES:
- Respond when @mentioned
- Respond to messages starting with !ask
- In the #support channel, respond to all messages
- In other channels, only respond when called

CAPABILITIES:
- Answer questions about [your topic/product/community]
- Help with technical troubleshooting
- Share relevant resources and links
- Summarize long discussions
- Draft announcements and updates

MODERATION ASSISTANCE:
- Flag potentially inappropriate content for moderators
- Warn users who violate community guidelines
- Do not ban, kick, or mute users autonomously
- Always defer to human moderators for enforcement actions

Step 6: Set Up Slash Commands (Optional)

Slash commands provide a structured way for users to interact with the bot:

Register Commands

Through the Discord skill configuration or the agent's admin API, register commands like:

/ask [question]       — Ask the AI a question
/summarize [topic]    — Get a summary of recent discussion on a topic
/help                 — Show what the bot can do
/faq                  — Show frequently asked questions
/feedback [message]   — Submit feedback to the server admins

Command Configuration Example

{
  "commands": [
    {
      "name": "ask",
      "description": "Ask the AI assistant a question",
      "options": [
        {
          "name": "question",
          "description": "Your question",
          "type": "STRING",
          "required": true
        }
      ]
    },
    {
      "name": "summarize",
      "description": "Summarize recent discussion on a topic",
      "options": [
        {
          "name": "topic",
          "description": "The topic to summarize",
          "type": "STRING",
          "required": true
        }
      ]
    }
  ]
}

Slash commands appear in Discord's command menu when users type /, providing a discoverable interface for your bot's features.

Step 7: Test the Bot

Verify everything works before announcing the bot to your community:

Test 1: Basic Response

In your Discord server, type:

@AI Assistant Hello! What can you do?

The bot should respond with its capabilities.

Test 2: Knowledge Question

@AI Assistant What is OpenClaw and how does it work?

The bot should provide an accurate answer using its knowledge base.

Test 3: Slash Command

Type /ask and wait for the command menu to appear. Enter a question and submit.

Test 4: DM Test

Send a direct message to the bot:

Can you help me with something?

If DM support is enabled, the bot should respond.

Test 5: Thread Continuity

Start a conversation with multiple follow-up messages. Verify the bot maintains context throughout.

Test 6: Long Response

Ask a complex question that requires a lengthy answer. Verify the bot correctly splits its response across multiple messages if needed (Discord has a 2000 character limit per message).

Step 8: Launch to Your Community

After successful testing, introduce the bot to your community:

Create a Bot Information Channel

Create a channel (e.g., #bot-info) with a pinned message explaining:

  • What the bot can do
  • How to interact with it (mention, prefix, slash commands)
  • What channels the bot is active in
  • Usage guidelines and expectations
  • Who to contact with issues or feedback

Gradual Rollout

Consider a phased rollout:

  1. Week 1 — Enable in one or two channels. Gather feedback from active members.
  2. Week 2 — Expand to more channels based on feedback. Adjust configuration as needed.
  3. Week 3 — Full rollout with refined settings.

This approach lets you catch issues early and refine the bot's behavior before it reaches your entire community.

Troubleshooting

Bot appears offline

  1. Check agent status — Verify the agent is "Running" on the EZClaws dashboard at /app.
  2. Verify bot token — Ensure the token in the skill configuration is correct and has not been regenerated.
  3. Check intents — Verify Message Content Intent is enabled in the Discord Developer Portal.
  4. Review logs — Check the agent's event log for connection errors.

Bot does not respond to messages

  1. Check trigger settings — Verify the bot is configured to respond to the type of message you are sending (mention, prefix, or all).
  2. Check channel permissions — Ensure the bot has permission to read and send messages in the channel.
  3. Verify credits — Check your credit balance at /app/billing.
  4. Check rate limits — Discord has rate limits on bot messages. If the bot has been very active, it may be temporarily throttled.

Bot gives incorrect or irrelevant answers

  1. Improve the system prompt — Add more specific instructions about your community's topics.
  2. Upgrade the model — Switch to a more capable model. See model configuration guide.
  3. Install knowledge skills — Add relevant knowledge from the marketplace at /app/marketplace.
  4. Enable memory — Persistent memory helps the bot improve over time. See memory guide.

Messages exceed Discord's character limit

  1. Instruct shorter responses — Add "Keep responses under 1800 characters" to the system prompt.
  2. Enable message splitting — Configure the skill to automatically split long messages.
  3. Use embeds — Discord embeds have a higher character limit (6000 characters) and look cleaner.

Advanced Features

Channel-Specific Behavior

Configure different behavior for different channels:

CHANNEL-SPECIFIC RULES:
- #general: Only respond when mentioned. Keep answers brief and friendly.
- #support: Respond to all messages. Provide detailed troubleshooting.
- #code-help: Respond when mentioned. Include code examples in responses.
- #off-topic: Do not respond unless directly asked.

Moderation Assistance

Your bot can assist with moderation (with appropriate permissions):

  • Detect and flag potentially inappropriate messages.
  • Warn users about rule violations.
  • Log flagged messages for moderator review.
  • Answer rule-related questions ("What are the server rules?").

Welcome New Members

Configure the bot to greet new members:

When a new member joins, send a DM welcoming them:
"Welcome to [Server Name]! I'm the AI assistant. Feel free to ask
me anything in the server channels. Type /help to see what I can do."

Summary

Creating a Discord bot with EZClaws connects your AI agent directly to your community. The setup takes about 15 minutes: create a Discord application, generate a bot token, install the Discord skill on your agent, and configure behavior.

A well-configured Discord bot enhances community engagement by providing instant answers, assisting with moderation, and automating routine tasks. Start with a small rollout, gather feedback, and expand as you refine the bot's behavior.

For other messaging integrations, explore our guides for Telegram, Slack, and WhatsApp. Visit the blog for more tips and the integrations page for a complete list of supported platforms.

Frequently Asked Questions

Yes. Creating a Discord bot through the Discord Developer Portal is completely free. You only pay for your EZClaws subscription and credit usage for LLM API calls.

Yes. A single Discord bot can be installed in multiple servers simultaneously. All servers share the same EZClaws agent, and each server's conversations are handled independently. Be aware that multi-server usage increases credit consumption.

With the right permissions and skills, your bot can assist with moderation tasks like detecting inappropriate content, warning users, and flagging messages for human moderators. It should be used alongside Discord's built-in moderation tools, not as a replacement.

Yes. Once a user shares a server with your bot, they can send direct messages to it. You can enable or disable DM functionality through the bot's configuration.

Configure the bot to only respond when mentioned (@BotName) or when a specific prefix is used (e.g., !ask). This is set up in the skill configuration and prevents the bot from processing every message in the channel.

Explore More

From the Blog

Ready to Deploy Your AI Agent?

Our provisioning engine spins up your private OpenClaw instance — dedicated VM, HTTPS endpoint, and full autonomy in under a minute.