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.
π‘ Quick Answer: Create a Discord application at
discord.com/developers, get the bot token, deploy OpenClaw with the token as a Secret, and configurechannels.discordinopenclaw.json. The bot responds to mentions in group channels and all DMs.env: - name: DISCORD_TOKEN valueFrom: secretKeyRef: name: openclaw-secrets key: DISCORD_TOKENKey concept: OpenClawβs Discord channel handles mention detection, thread management, and message routing automatically. Configure
requireMention: truefor group channels.Gotcha: Discord bots need the
MESSAGE_CONTENTprivileged 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 --> PVCStep 1: Create the Discord Application
- Go to Discord Developer Portal
- Click New Application β name it
- Go to Bot β click Reset Token β copy the token
- Enable MESSAGE CONTENT INTENT under Privileged Gateway Intents
- Go to OAuth2 β URL Generator β select
botscope β select permissions:- Send Messages, Read Message History, Use Slash Commands, Add Reactions
- 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-configkubectl apply -f openclaw-discord.yamlStep 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 statusIssue 2: Bot responds to every message in group channels
// Set requireMention to true
{
"messages": {
"groupChat": {
"requireMention": true
}
}
}Best Practices
- Enable MESSAGE_CONTENT intent β Required for reading message text
- Use requireMention in groups β Prevents the bot from responding to every message
- Set a custom SOUL.md β Define the botβs personality and expertise area
- Use Recreate strategy β Only one instance should connect to Discord at a time
- 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

Recommended
Kubernetes Recipes β The Complete Book100+ production-ready patterns with detailed explanations, best practices, and copy-paste YAML. Everything in one place.
Get the Book βLearn by Doing
CopyPasteLearn β Hands-on Cloud & DevOps CoursesMaster Kubernetes, Ansible, Terraform, and MLOps with interactive, copy-paste-run lessons. Start free.
Browse Courses βπ Deepen Your Skills β Hands-on Courses
Courses by CopyPasteLearn.com β Learn IT by Doing
