Skip to content

feat(discord): support role mention as trigger (allowed_role_ids) #758

@chaodu-agent

Description

@chaodu-agent

Problem

Currently, the only way to trigger the bot is via direct @mention (<@BOT_ID>). When multiple bots are deployed (e.g. 4+ agents), users must type each bot mention individually:

@超渡法師 @普渡法師 @擺渡法師 @覺渡法師 review this PR

Discord supports role mentions (@RoleName) which notify all members of that role. If we create a role (e.g. @法師團) and assign all bots to it, a single @法師團 should trigger all bots simultaneously.

Proposed Solution

Add allowed_role_ids config field to DiscordConfig. When a message mentions a role in this list, treat it as equivalent to a direct @mention for trigger purposes.

Config

[discord]
# Role IDs that trigger the bot (same as direct @mention)
allowed_role_ids = ["1234567890"]

Implementation

  1. src/config.rs — Add allowed_role_ids: Vec<String> to DiscordConfig (default empty = disabled)
  2. src/discord.rs — Extend is_mentioned check:
    let is_mentioned = msg.mentions_user_id(bot_id)
        || msg.content.contains(&format!("<@{}>", bot_id))
        || (!self.allowed_role_ids.is_empty()
            && msg.mention_roles.iter().any(|r| self.allowed_role_ids.contains(&r.get())));
  3. resolve_mentions() — Strip the triggering role mention from prompt (like we strip bot mention), keep other role mentions as @(role)
  4. Helm chart — Add allowedRoleIds to values.yaml + render in configmap.yaml

Behavior

  • Empty allowed_role_ids (default) = no change, role mentions ignored as before
  • Non-empty = role mention treated as trigger, same as direct @mention
  • Works with all allow_user_messages modes (Mentions, Involved, MultibotMentions)
  • Role mention stripped from prompt sent to agent (same as bot mention)

Use Case

Discord server with multiple OpenAB bots. Create a @Bots role, assign all bots, configure each bot with that role ID. Users type @Bots do something and all bots respond.

Discord Discussion

https://discord.com/channels/1488041051187974246/1501546581105705012

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions