Skip to content

feat(discord): add multibot-mentions mode for allow_user_messages #463

@chaodu-agent

Description

@chaodu-agent

Problem

With allow_user_messages = "involved", a bot responds to all messages in threads it has participated in — no @mention required. In multi-bot threads (where multiple bots are active), this causes every bot to respond to every message, creating noise and confusion.

The mentions mode fixes this but is too strict — it requires @mention even in single-bot threads where the conversational flow is natural.

Proposal

Add a third mode: multibot-mentions

[discord]
allow_user_messages = "multibot-mentions"

Behavior:

  • Single-bot threads: same as involved — no @mention needed if the bot has participated
  • Multi-bot threads: falls back to mentions — requires explicit @mention to respond

How to detect multi-bot threads

bot_participated_in_thread() already fetches up to 200 recent messages. We can check in the same fetch whether any other bot (from trusted_bot_ids or m.author.bot) has posted:

let involved = messages.iter().any(|m| m.author.id == bot_id);
let other_bot_involved = messages.iter().any(|m|
    m.author.bot && m.author.id != bot_id
);

Then in the gating logic:

AllowUsers::MultibotMentions => {
    if !in_thread { return; }
    let (involved, other_bot) = self
        .check_thread_participation(&ctx.http, msg.channel_id, bot_id)
        .await;
    if !involved { return; }
    if other_bot { return; } // multi-bot thread → require @mention
}

Cost

  • Zero additional API calls — reuses existing message fetch
  • Backward compatible — new opt-in mode, default unchanged
  • Config change — one new variant in AllowUsers enum

Edge cases

  • First message in thread: no other bot messages yet → behaves as involved (correct, not yet a multi-bot thread)
  • trusted_bot_ids not set: can fall back to m.author.bot to detect any bot, not just trusted ones
  • Participation cache: needs to expand from bool to include other_bot_present flag, or use a separate cache

Related

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