openclaw - 💡(How to fix) Fix feat(discord): treat role mentions as explicit mentions for mention-gated agents [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#59151Fetched 2026-04-08 02:28:05
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Root Cause

In the Discord inbound handler, explicitlyMentioned only checks message.mentionedUsers:

const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user) => user.id === botId)
);

Role mentions are already tracked and used for ignoreOtherMentions filtering:

const hasAnyMention = Boolean(!isDirectMessage && (
  (message.mentionedUsers?.length ?? 0) > 0 ||
  (message.mentionedRoles?.length ?? 0) > 0 ||
  message.mentionedEveryone && (!author.bot || sender.isPluralKit)
));

But hasAnyMention does not feed into wasMentioned for the bot itself. The message is dropped by the mention gate before any plugin hook (message_received) fires, so plugins cannot work around this.

Code Example

const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user) => user.id === botId)
);

---

const hasAnyMention = Boolean(!isDirectMessage && (
  (message.mentionedUsers?.length ?? 0) > 0 ||
  (message.mentionedRoles?.length ?? 0) > 0 ||
  message.mentionedEveryone && (!author.bot || sender.isPluralKit)
));

---

// Existing
const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user) => user.id === botId)
);

// New: role-based mention detection
const mentionedViaRole = Boolean(
  !isDirectMessage &&
  botMemberRoleIds?.length &&
  message.mentionedRoles?.some(r => botMemberRoleIds.includes(r.id))
);

// New: @everyone/@here detection
const mentionedViaEveryone = Boolean(
  !isDirectMessage &&
  message.mentionedEveryone &&
  !author.bot  // prevent bot @everyone from triggering other bots
);

// Feed combined result into mention gate
const effectiveExplicit = explicitlyMentioned || mentionedViaRole || mentionedViaEveryone;

---

{
  channels: {
    discord: {
      guilds: {
        "<guild_id>": {
          mentionRolesAsExplicit: true,  // default: true
          mentionEveryoneAsExplicit: false  // default: false (safety)
        }
      }
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

When a Discord role (e.g. @dev-team, @engineers) is mentioned in a guild message, agents assigned to that role do not receive the message. The mention gate drops it because role mentions are not counted as explicit bot mentions.

@everyone and @here have the same issue — they do not trigger agent responses.

Root Cause

In the Discord inbound handler, explicitlyMentioned only checks message.mentionedUsers:

const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user) => user.id === botId)
);

Role mentions are already tracked and used for ignoreOtherMentions filtering:

const hasAnyMention = Boolean(!isDirectMessage && (
  (message.mentionedUsers?.length ?? 0) > 0 ||
  (message.mentionedRoles?.length ?? 0) > 0 ||
  message.mentionedEveryone && (!author.bot || sender.isPluralKit)
));

But hasAnyMention does not feed into wasMentioned for the bot itself. The message is dropped by the mention gate before any plugin hook (message_received) fires, so plugins cannot work around this.

Expected Behavior

If a message mentions a Discord role that the bot user is a member of, the bot should treat it as wasMentioned = true and process the message normally.

Similarly, @everyone should trigger all agents that have channel access.

Proposed Fix

After the existing explicitlyMentioned check, add role and everyone detection:

// Existing
const explicitlyMentioned = Boolean(
  botId && message.mentionedUsers?.some((user) => user.id === botId)
);

// New: role-based mention detection
const mentionedViaRole = Boolean(
  !isDirectMessage &&
  botMemberRoleIds?.length &&
  message.mentionedRoles?.some(r => botMemberRoleIds.includes(r.id))
);

// New: @everyone/@here detection
const mentionedViaEveryone = Boolean(
  !isDirectMessage &&
  message.mentionedEveryone &&
  !author.bot  // prevent bot @everyone from triggering other bots
);

// Feed combined result into mention gate
const effectiveExplicit = explicitlyMentioned || mentionedViaRole || mentionedViaEveryone;

The bot's role IDs (botMemberRoleIds) should be available from the guild member cache or fetchable via GET /guilds/{guild_id}/members/{bot_id}.

This is a ~10 line change. All the data (mentionedRoles, mentionedEveryone) is already computed — it just needs to be wired into the mention gate.

Optional: Config guard

A config flag could make this opt-in:

{
  channels: {
    discord: {
      guilds: {
        "<guild_id>": {
          mentionRolesAsExplicit: true,  // default: true
          mentionEveryoneAsExplicit: false  // default: false (safety)
        }
      }
    }
  }
}

Use Case

Multi-agent setups where a human wants to address a group of agents at once:

  • @dev-team standup please → all agents in the dev-team role respond
  • @agents status report → all agent bots respond
  • @everyone meeting in 5 → reaches humans AND agents

Environment

  • OpenClaw version: 2026.3.x
  • Channel: Discord
  • Config: requireMention: true (default for guild channels)

extent analysis

TL;DR

To fix the issue where Discord role mentions do not trigger agent responses, update the mention gate logic to include role-based mention detection and @everyone detection.

Guidance

  • Modify the explicitlyMentioned check to include mentionedViaRole and mentionedViaEveryone conditions.
  • Ensure the bot's role IDs (botMemberRoleIds) are available from the guild member cache or fetchable via the Discord API.
  • Consider adding a config flag to make this behavior opt-in, with separate flags for role mentions and @everyone mentions.
  • Verify the fix by testing role mentions and @everyone mentions in a guild channel.

Example

const mentionedViaRole = Boolean(
  !isDirectMessage &&
  botMemberRoleIds?.length &&
  message.mentionedRoles?.some(r => botMemberRoleIds.includes(r.id))
);

const mentionedViaEveryone = Boolean(
  !isDirectMessage &&
  message.mentionedEveryone &&
  !author.bot
);

const effectiveExplicit = explicitlyMentioned || mentionedViaRole || mentionedViaEveryone;

Notes

This fix assumes that the mentionedRoles and mentionedEveryone data is already computed and available. If this data is not available, additional changes may be required to compute it.

Recommendation

Apply the proposed fix to update the mention gate logic, as it provides a clear and concise solution to the issue. This fix should be applied to the OpenClaw version 2026.3.x, and the config flag can be used to control the behavior.

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