claw-log

Discord channel as AI context

Bot setup, privileged intents, per-channel sessions, and the gotcha that breaks 80% of installs.

Before you start: You need a Discord account and a private Discord server. If you don't have one, create one: + → Create My Own → For me and my friends. Keep it private — this is your personal agent workspace, not a public community.

1
Create a Discord application and bot
  1. Go to discord.com/developers/applications
  2. Click New Application
  3. Name it (e.g. "OpenClaw" or your agent's name) → click Create
  4. In the left sidebar, click Bot
  5. Set the Username to your agent's name
  6. Optionally upload a profile picture
2
Enable privileged intents

Still on the Bot page, scroll down to Privileged Gateway Intents. This is where most installs go wrong — if Message Content Intent is not enabled, the bot connects but can't read any messages.

Message Content Intent Required — without this the bot is blind
Server Members Intent Required for role allowlists + name matching
Presence Intent Optional — only for presence/status features

If you skip Message Content Intent: the bot will appear online in Discord but won't respond to any messages. This is the most common setup failure. You have to go back to the Developer Portal, enable the intent, and restart the gateway.

3
Copy your bot token

Scroll back to the top of the Bot page. Click Reset Token (despite the name, this generates your first token — it's not actually resetting anything).

Copy the token and save it somewhere safe. You'll use it in Step 6. This token is like a password — anyone with it can control your bot.

Never paste your bot token into a chat message — including to OpenClaw. You'll set it via the command line or config file only. Discord automatically invalidates tokens that appear in public messages.

4
Generate an invite URL and add the bot to your server

In the left sidebar, click OAuth2 → scroll down to OAuth2 URL Generator.

Check these two scopes:

A Bot Permissions section appears below. Enable these:

View Channels
Send Messages
Read Message History
Embed Links
Attach Files
Add ReactionsOptional

Copy the generated URL at the bottom. Paste it into your browser, select your private server, click ContinueAuthorize. The bot should now appear in your server's member list (offline until the gateway starts).

5
Enable Developer Mode and collect your IDs

You need three IDs: your Server ID, your User ID, and optionally channel IDs. To copy them, Developer Mode must be on.

  1. User Settings (gear icon next to your avatar, bottom left) → Advanced → toggle on Developer Mode
  2. Right-click your server icon in the sidebar → Copy Server ID
  3. Right-click your own avatar anywhere in the server → Copy User ID

To copy a channel ID: right-click any channel name in the sidebar → Copy Channel ID. You'll need this for cron delivery and webhook delivery targets.

6
Set the bot token (securely)

Set the token as an environment variable and configure OpenClaw to use it — never put the token in plaintext in config:

# Set the token as an env var on the machine running OpenClaw
export DISCORD_BOT_TOKEN="YOUR_BOT_TOKEN_HERE"

# Tell OpenClaw to read the token from env
openclaw config set channels.discord.token --ref-provider default --ref-source env --ref-id DISCORD_BOT_TOKEN

# Enable Discord
openclaw config set channels.discord.enabled true --strict-json

# Start the gateway (or restart if already running)
openclaw gateway start

Alternatively, set it in config with an env reference (SOPS-compatible):

{
  channels: {
    discord: {
      enabled: true,
      token: {
        source: "env",
        provider: "default",
        id: "DISCORD_BOT_TOKEN",
      },
    },
  },
}
7
Allow DMs from server members

For pairing to work via DM, Discord must allow server bots to message you. In the Discord app:

  1. Right-click your server iconPrivacy Settings
  2. Toggle on Direct Messages
8
Approve your first DM pairing

Once the gateway is running, DM your bot in Discord. It will respond with a pairing code. Approve it:

# List pending pairing requests
openclaw pairing list discord

# Approve the code (replace 1234 with the actual code)
openclaw pairing approve discord 1234

Pairing codes expire after 1 hour. After approval, you can chat with your agent via Discord DM.


Guild workspace: per-channel sessions

DMs work in a single shared session. A guild workspace is more powerful: each Discord channel gets its own isolated agent session with its own context. You can have #coding, #home, #research, #finance — each with a distinct conversation history the agent treats separately.

1. Add your server to the guild allowlist

{
  channels: {
    discord: {
      enabled: true,
      token: { source: "env", provider: "default", id: "DISCORD_BOT_TOKEN" },

      groupPolicy: "allowlist",
      guilds: {
        "YOUR_SERVER_ID": {
          // Require @mention in channels (set false for fully private server)
          requireMention: true,
          // Only these users can interact via channels
          users: ["YOUR_USER_ID"],
        },
      },
    },
  },
}

2. For a fully private server: disable @mention requirement

If it's just you and your bot, you don't need to @mention it every message:

{
  channels: {
    discord: {
      guilds: {
        "YOUR_SERVER_ID": {
          requireMention: false,  // responds to every message in allowed channels
          users: ["YOUR_USER_ID"],
        },
      },
    },
  },
}

3. Set up your channel structure

Create channels in your Discord server for different contexts. The agent sees the channel name and each gets its own session:

Memory in guild channels: MEMORY.md only auto-loads in DM sessions, not guild channels. For guild channel context, put stable facts in AGENTS.md or USER.md (loaded everywhere). Use memory_search or memory_get when you need long-term context inside a channel session.

Cron delivery to Discord channels

# Deliver a morning brief to a specific Discord channel
openclaw cron add \
  --name "Morning Brief" \
  --cron "0 7 * * 1-5" \
  --tz "America/New_York" \
  --exact \
  --session isolated \
  --message "Morning brief: top priorities, calendar, anything urgent." \
  --announce \
  --channel discord \
  --to "YOUR_CHANNEL_ID" \
  --model openrouter/meta-llama/llama-3.3-70b-instruct:free

Get your channel ID: right-click any channel in the Discord sidebar (with Developer Mode on) → Copy Channel ID.


Troubleshooting

Bot appears online but doesn't respond to messages
Missing Message Content Intent. Go to Discord Developer Portal → your application → Bot → Privileged Gateway Intents → enable "Message Content Intent" → save → restart the gateway. This is the #1 failure mode.
Bot responds to DMs but not in server channels
Your server isn't in the guild allowlist. Add it to channels.discord.guilds in config with your Server ID. Also check that groupPolicy is set to "allowlist" and your User ID is in the users array.
Can't DM the bot / bot can't DM me
Discord Privacy Settings are blocking it. Right-click your server icon → Privacy Settings → toggle on "Direct Messages". This allows bots in that server to DM you.
Pairing code expired / never received one
Codes expire after 1 hour. DM the bot again to generate a new one. If no DM arrives, check that the gateway is running (openclaw gateway status) and that DMs are allowed in your server Privacy Settings.
Token invalid / bot goes offline shortly after starting
The token was likely regenerated in the Developer Portal. Go back to the Bot page, click Reset Token again, copy the new token, update your env var or SOPS secret, and restart the gateway.
Cron delivery to Discord not working
Check the channel ID is correct (copy from Discord with Developer Mode on, not from the URL). Also verify the bot has "Send Messages" permission in that specific channel — check channel-level permission overrides in Discord, not just server-level.