πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Deployments beginner ⏱ 15 minutes K8s 1.28+

Run an OpenClaw Discord Bot on Kubernetes

Deploy OpenClaw as a Discord bot on Kubernetes with channel routing, mention handling, group chat rules, and persistent conversation memory.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: Create a Discord application at discord.com/developers, get the bot token, deploy OpenClaw with the token as a Secret, and configure channels.discord in openclaw.json. The bot responds to mentions in group channels and all DMs.

env:
  - name: DISCORD_TOKEN
    valueFrom:
      secretKeyRef:
        name: openclaw-secrets
        key: DISCORD_TOKEN

Key concept: OpenClaw’s Discord channel handles mention detection, thread management, and message routing automatically. Configure requireMention: true for group channels.

Gotcha: Discord bots need the MESSAGE_CONTENT privileged intent enabled in the Developer Portal, otherwise they can’t read message text.

The Problem

Building a Discord bot with AI capabilities requires:

  • SDK boilerplate for handling events, commands, and message routing
  • Session management to maintain conversation context per user/channel
  • Mention handling to only respond when addressed in busy channels
  • Memory persistence across bot restarts

The Solution

OpenClaw handles all Discord integration out of the box β€” just provide the bot token and configure routing rules.

Architecture Overview

flowchart LR
    subgraph discord["Discord"]
        DM["DMs"]
        CH["#general"]
        TH["Threads"]
    end
    subgraph k8s["☸️ Kubernetes"]
        GW["OpenClaw<br/>Gateway"]
        PVC["PVC<br/>Sessions"]
    end
    
    DM & CH & TH --> GW
    GW --> PVC

Step 1: Create the Discord Application

  1. Go to Discord Developer Portal
  2. Click New Application β†’ name it
  3. Go to Bot β†’ click Reset Token β†’ copy the token
  4. Enable MESSAGE CONTENT INTENT under Privileged Gateway Intents
  5. Go to OAuth2 β†’ URL Generator β†’ select bot scope β†’ select permissions:
    • Send Messages, Read Message History, Use Slash Commands, Add Reactions
  6. Open the generated URL to invite the bot to your server

Step 2: Deploy on Kubernetes

# openclaw-discord.yaml
apiVersion: v1
kind: Secret
metadata:
  name: openclaw-secrets
  namespace: openclaw
type: Opaque
stringData:
  ANTHROPIC_API_KEY: "sk-ant-your-key"
  DISCORD_TOKEN: "your-discord-bot-token"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: openclaw-config
  namespace: openclaw
data:
  openclaw.json: |
    {
      "gateway": { "port": 18789 },
      "channels": {
        "discord": {
          "enabled": true
        }
      },
      "messages": {
        "groupChat": {
          "requireMention": true,
          "mentionPatterns": ["@openclaw"]
        }
      }
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: openclaw-discord
  namespace: openclaw
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: openclaw-discord
  template:
    metadata:
      labels:
        app: openclaw-discord
    spec:
      containers:
        - name: openclaw
          image: node:22-slim
          command: ["sh", "-c", "npm i -g openclaw@latest && openclaw gateway"]
          envFrom:
            - secretRef:
                name: openclaw-secrets
          volumeMounts:
            - name: state
              mountPath: /home/node/.openclaw
            - name: config
              mountPath: /home/node/.openclaw/openclaw.json
              subPath: openclaw.json
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
            limits:
              cpu: "1"
              memory: 1Gi
      volumes:
        - name: state
          persistentVolumeClaim:
            claimName: openclaw-state
        - name: config
          configMap:
            name: openclaw-config
kubectl apply -f openclaw-discord.yaml

Step 3: Configure Group Chat Behavior

{
  "channels": {
    "discord": {
      "enabled": true,
      "groups": {
        "*": {
          "requireMention": true
        },
        "123456789012345678": {
          "requireMention": false,
          "allowFrom": ["987654321098765432"]
        }
      }
    }
  }
}

Step 4: Customize the Bot Persona

# Edit the workspace SOUL.md to define the bot's personality
kubectl exec -n openclaw deploy/openclaw-discord -- sh -c 'cat > /home/node/.openclaw/workspace/SOUL.md << EOF
# Discord Community Bot

You are a helpful Kubernetes expert in the kubernetes.recipes Discord server.
Be concise, use code blocks for YAML/commands, and react with emoji when appropriate.
Stay on topic β€” Kubernetes, containers, cloud native.
EOF'

Common Issues

Issue 1: Bot not responding to mentions

# Verify MESSAGE_CONTENT intent is enabled in Discord Developer Portal
# Check logs for connection status
kubectl logs -n openclaw deploy/openclaw-discord | grep -i discord

# Verify the bot is connected
kubectl exec -n openclaw deploy/openclaw-discord -- openclaw status

Issue 2: Bot responds to every message in group channels

// Set requireMention to true
{
  "messages": {
    "groupChat": {
      "requireMention": true
    }
  }
}

Best Practices

  1. Enable MESSAGE_CONTENT intent β€” Required for reading message text
  2. Use requireMention in groups β€” Prevents the bot from responding to every message
  3. Set a custom SOUL.md β€” Define the bot’s personality and expertise area
  4. Use Recreate strategy β€” Only one instance should connect to Discord at a time
  5. Monitor token rotation β€” Discord tokens don’t expire but should be rotated periodically

Key Takeaways

  • OpenClaw handles Discord integration β€” No custom bot code needed
  • Mention-based routing keeps the bot quiet in busy channels
  • SOUL.md defines persona β€” Customize the bot’s personality via workspace files
  • Persistent storage maintains conversation history and context across restarts
  • Single replica is required β€” Discord only allows one active connection per bot token
#openclaw #discord #bot #ai-agent #chatbot #deployment
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens