Skip to content

Commit eb0087d

Browse files
authored
fix(discord): connect mention-only bots without Message Content intent (#116962)
* fix(discord): support mention-only gateway intent * chore: keep release changelog owner-only
1 parent 8b93fd9 commit eb0087d

9 files changed

Lines changed: 56 additions & 19 deletions

File tree

‎docs/channels/discord.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Create a Discord application with a bot, add the bot to your server, and pair it
3434
<Step title="Enable privileged intents">
3535
Still on the **Bot** page, under **Privileged Gateway Intents** enable:
3636

37-
- **Message Content Intent** (required)
37+
- **Message Content Intent** (required for normal guild messages)
3838
- **Server Members Intent** (recommended; required for role allowlists, name-to-ID matching, and channel-audience access groups)
3939
- **Presence Intent** (optional; only for presence updates)
4040

@@ -203,6 +203,12 @@ openclaw pairing approve discord <CODE>
203203
</Step>
204204
</Steps>
205205

206+
If Discord cannot grant Message Content Intent, OpenClaw can still operate in DMs and in
207+
guild channels where users explicitly mention the bot. Set
208+
`channels.discord.intents.messageContent: false` so the Gateway does not request the
209+
unavailable privileged intent, and keep `requireMention: true` on every configured guild
210+
channel. Discord omits user-authored content from other guild messages in this mode.
211+
206212
<Note>
207213
Token resolution is account-aware. Config token values win over the env fallback, and `DISCORD_BOT_TOKEN` is only used for the default account.
208214
If two enabled Discord accounts resolve to the same bot token, OpenClaw starts only one gateway monitor for that token: a config-sourced token wins over the env fallback; otherwise the first enabled account wins and the duplicate account is reported disabled with reason `duplicate bot token`.

‎docs/gateway/config-channels.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ WhatsApp runs through the gateway's web channel (Baileys Web). It starts automat
371371
- `channels.discord.streaming` is the canonical stream mode key. Discord defaults to `streaming.mode: "progress"` so tool/work progress appears in one edited preview message; set `streaming.mode: "off"` to disable it. Legacy flat keys (`streamMode`, `chunkMode`, `blockStreaming`, `draftChunk`, `blockStreamingCoalesce`) are no longer read at runtime; run `openclaw doctor --fix` to migrate persisted config.
372372
- `channels.discord.autoPresence` maps runtime availability to bot presence (healthy => online, degraded => idle, exhausted => dnd) and allows optional status text overrides.
373373
- `channels.discord.guilds.<id>.presenceEvents` routes human availability arrivals into one configured Discord channel as agent system events. Eligible members must be able to view `channelId`; public threads inherit parent visibility, while private threads additionally require membership or Manage Threads. `users` can further narrow that audience. It seeds current online members from complete `GUILD_CREATE` snapshots, routes observed offline-to-online transitions, and treats a first later online signal for an unseen member as newly available without asserting whether they came online or joined after the snapshot. Guilds above Discord's 75,000-member snapshot limit require an explicit offline update first. Throttling knobs: `reconnectSuppressSeconds` (quiet window after a new Gateway session while guild presence state is rebuilt, default 300, `0` disables) and `burstLimit`/`burstWindowSeconds` (per-guild successfully queued event rate limit, default 8 events per 60s sliding window). Resumed sessions do not start the reconnect suppression window. The existing per-user re-greet cooldown remains eight hours. It requires `channels.discord.intents.presence=true`, the privileged Presence Intent in Discord's Developer Portal, and an enabled agent heartbeat.
374+
- `channels.discord.intents.messageContent` defaults to `true`. Set it to `false` only for mention-only operation when Discord cannot grant the privileged Message Content intent; DMs and explicit bot mentions still carry message content, while other guild messages do not. Keep `requireMention: true` on every configured guild channel in this mode.
374375
- `channels.discord.dangerouslyAllowNameMatching` re-enables mutable name/tag matching (break-glass compatibility mode).
375376
- `channels.discord.execApprovals`: Discord-native exec approval delivery and approver authorization.
376377
- `enabled`: `true`, `false`, or `"auto"` (default). In auto mode, exec approvals activate when approvers can be resolved from `approvers` or `commands.ownerAllowFrom`.

‎extensions/discord/src/config-schema.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ describe("discord config schema", () => {
422422
);
423423
});
424424

425+
it("accepts mention-only gateway intent mode", () => {
426+
const cfg = expectValidDiscordConfig({
427+
intents: { messageContent: false },
428+
});
429+
430+
expect(cfg.intents?.messageContent).toBe(false);
431+
});
432+
425433
it("accepts online-presence throttling knobs", () => {
426434
const cfg = expectValidDiscordConfig({
427435
intents: { presence: true },

‎extensions/discord/src/config-schema.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ const DiscordAccountSchema = z
281281
.optional(),
282282
intents: z
283283
.object({
284+
messageContent: z.boolean().optional(),
284285
presence: z.boolean().optional(),
285286
guildMembers: z.boolean().optional(),
286287
voiceStates: z.boolean().optional(),

‎extensions/discord/src/config-ui-hints.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export const discordChannelConfigUiHints = {
7777
label: "Discord Component TTL (ms)",
7878
help: "How long sent Discord component callbacks remain registered. Default is 1800000 (30 minutes); maximum is 86400000 (24 hours).",
7979
},
80+
"intents.messageContent": {
81+
label: "Discord Message Content Intent",
82+
help: "Request the privileged Message Content intent (default: true). Set false only for mention-only guild operation when Discord cannot grant the intent; DMs and explicit mentions still include message content.",
83+
},
8084
"intents.presence": {
8185
label: "Discord Presence Intent",
8286
help: "Enable the Guild Presences privileged intent. Must also be enabled in the Discord Developer Portal. Allows tracking user activities (e.g. Spotify). Default: false.",

‎extensions/discord/src/monitor/gateway-plugin.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ describe("createDiscordGatewayPlugin", () => {
116116
expect(intents & GatewayIntents.GuildVoiceStates).toBe(0);
117117
});
118118

119+
it("omits MessageContent only when explicitly disabled", () => {
120+
const defaultIntents = resolveDiscordGatewayIntents();
121+
const mentionOnlyIntents = resolveDiscordGatewayIntents({
122+
intentsConfig: { messageContent: false },
123+
});
124+
125+
expect(defaultIntents & GatewayIntents.MessageContent).toBe(GatewayIntents.MessageContent);
126+
expect(mentionOnlyIntents & GatewayIntents.MessageContent).toBe(0);
127+
});
128+
119129
it("lets intents.voiceStates override voice enablement", () => {
120130
const enabled = resolveDiscordGatewayIntents({
121131
intentsConfig: { voiceStates: true },

‎extensions/discord/src/monitor/gateway-plugin.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ export function resolveDiscordGatewayIntents(params?: ResolveDiscordGatewayInten
172172
let intents =
173173
discordGateway.GatewayIntents.Guilds |
174174
discordGateway.GatewayIntents.GuildMessages |
175-
discordGateway.GatewayIntents.MessageContent |
176175
discordGateway.GatewayIntents.DirectMessages |
177176
discordGateway.GatewayIntents.GuildMessageReactions |
178177
discordGateway.GatewayIntents.DirectMessageReactions;
178+
if (intentsConfig?.messageContent !== false) {
179+
intents |= discordGateway.GatewayIntents.MessageContent;
180+
}
179181
if (voiceStatesEnabled) {
180182
intents |= discordGateway.GatewayIntents.GuildVoiceStates;
181183
}

‎src/config/bundled-channel-config-metadata.generated.ts‎

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

‎src/config/types.discord.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ export type DiscordActionConfig = {
112112
};
113113

114114
export type DiscordIntentsConfig = {
115+
/**
116+
* Request the privileged Message Content intent. Disable only for mention-only guild operation;
117+
* Discord still includes content in DMs and messages that explicitly mention the bot. Default: true.
118+
*/
119+
messageContent?: boolean;
115120
/** Enable Guild Presences privileged intent (requires Portal opt-in). Default: false. */
116121
presence?: boolean;
117122
/** Enable Guild Members privileged intent (requires Portal opt-in). Default: false. */

0 commit comments

Comments
 (0)