openclaw - ✅(Solved) Fix [Bug]: Discord mention detection fails when mentionedUsers array is empty [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44524Fetched 2026-04-08 00:45:46
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Author
Participants
Timeline (top)
referenced ×4cross-referenced ×3

Root Cause

// src/discord/monitor/message-handler.preflight.ts:407-409
const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user: User) => user.id === botId),
);

No fallback exists when mentionedUsers is empty. By contrast, Slack uses text-based mention detection (message.text?.includes(<@botId>)) and is not affected.

Fix Action

Fixed

PR fix notes

PR #44526: fix(discord): add content-based mention detection fallback

Description (problem / solution / changelog)

Summary

  • Add content-based fallback to Discord's explicitlyMentioned detection when message.mentionedUsers array is empty
  • Covers both standard (<@id>) and legacy nickname (<@!id>) Discord mention formats
  • Fixes cases where Discord API doesn't consistently populate mentionedUsers in threads

Closes #44524 Related: #44183

Changes

FileChange
src/discord/monitor/message-handler.preflight.ts:407-412Add message.content text parsing fallback to explicitlyMentioned
src/discord/monitor/message-handler.preflight.test.ts3 new test cases

Before: explicitlyMentioned relies solely on message.mentionedUsers array (Discord API structured field).

After: Falls back to parsing message.content for <@botId> or <@!botId> when mentionedUsers doesn't contain the bot.

Why Slack is not affected: Slack already uses text-based mention detection (message.text?.includes(<@botId>)).

Test plan

  • Detects mention when mentionedUsers is empty but content contains <@botId>
  • Detects mention when mentionedUsers is empty but content contains legacy <@!botId>
  • Drops message when mentionedUsers is empty and content has no mention (preserves existing behavior)
  • All 19 existing preflight tests still pass

🤖 Generated with Claude Code

Changed files

  • src/discord/monitor/message-handler.preflight.test.ts (modified, +77/-0)
  • src/discord/monitor/message-handler.preflight.ts (modified, +5/-1)

PR #44545: fix(discord): add content-based fallback for mention detection

Description (problem / solution / changelog)

Summary

Added a content-based fallback to detect mentions via message.content when mentionedUsers doesn't contain the bot. This ensures mentions are not missed in certain scenarios (e.g. threads).

Resolves #44524

Problem statement

Discord's mention detection relies solely on the message.mentionedUsers array. In certain scenarios, Discord may not consistently populate this array even when the message content clearly contains @Bot mentions. This causes explicitlyMentioned to evaluate to false, and the message is dropped.

Proposed solution

Add content-based fallback checking message.content?.includes(<@${botId}>) and message.content?.includes(<@!${botId}>) to robustly detect standard and legacy mention formats when mentionedUsers fails us.

Acceptance criteria

Discord mentions in threads or channel main areas without correct mentionedUsers population are now properly detected by checking message content.

Changed files

  • src/discord/monitor/message-handler.preflight.ts (modified, +4/-1)
  • ui/src/ui/views/agents-utils.test.ts (modified, +5/-2)

Code Example

// src/discord/monitor/message-handler.preflight.ts:407-409
const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user: User) => user.id === botId),
);
RAW_BUFFERClick to expand / collapse

Bug Description

Discord's mention detection in message-handler.preflight.ts relies solely on the message.mentionedUsers array populated by the Discord API. In certain scenarios (particularly new threads and some channel contexts), Discord may not consistently populate this array even when the message content clearly contains @Bot mentions.

This causes explicitlyMentioned to evaluate to false, and the message is dropped by the mention gate with a no-mention log entry.

Root Cause

// src/discord/monitor/message-handler.preflight.ts:407-409
const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user: User) => user.id === botId),
);

No fallback exists when mentionedUsers is empty. By contrast, Slack uses text-based mention detection (message.text?.includes(<@botId>)) and is not affected.

Related

  • #44183 — reports the same symptom: bot responds in original thread but fails in new threads and channel main area with no-mention log

Proposed Fix

Add content-based fallback to detect mentions via message.content when mentionedUsers doesn't contain the bot, covering both standard (<@id>) and legacy (<@!id>) Discord mention formats.

extent analysis

Fix Plan

To address the issue, we need to modify the explicitlyMentioned check to include a fallback that scans the message.content for mentions. Here are the steps:

  • Update the message-handler.preflight.ts file to include the content-based mention detection.
  • Use a regular expression to match both standard (<@id>) and legacy (<@!id>) Discord mention formats.

Example Code

const explicitlyMentioned = Boolean(
  botId && (
    message.mentionedUsers?.some((user: User) => user.id === botId) ||
    new RegExp(`(<@|<@!)${botId}>`).test(message.content)
  ),
);

This code checks if the mentionedUsers array contains the bot ID, and if not, it uses a regular expression to scan the message.content for mentions.

Verification

To verify the fix, test the following scenarios:

  • Send a message with a standard mention (@Bot) in a new thread and channel main area.
  • Send a message with a legacy mention (@!Bot) in a new thread and channel main area.
  • Check the logs to ensure that the no-mention log entry is no longer present.

Extra Tips

  • Make sure to update the regular expression to match the correct bot ID format.
  • Consider adding additional logging to track the number of times the fallback detection is used.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING