Skip to content

fix(discord): multibot-mentions fails to detect other bots due to gating order #481

@thepagent

Description

@thepagent

Description

multibot-mentions mode fails to detect multi-bot threads when allow_bot_messages = "mentions". The bot responds without @mention even after another bot has posted in the thread.

Root cause: Eager multibot detection (line 335) runs after bot message gating (line 248). When another bot posts without @mentioning this bot, the message is discarded at the gating step and never reaches the detection code.

Bot gating (line 248)              ← other bot msg filtered here
  → return if bot msg
...
Eager multibot detection (line 335) ← never reached
  → multibot_threads.insert(key)

https://github.com/openabdev/openab/blob/9b7680d/src/discord.rs#L248

https://github.com/openabdev/openab/blob/9b7680d/src/discord.rs#L335

Steps to Reproduce

  1. Set allow_bot_messages = "mentions" and allow_user_messages = "multibot-mentions"
  2. Human: @BotA HIHI → BotA creates thread, responds
  3. Human: @BotB 你來 → BotB responds in the thread
  4. Human: nice (no @mention) → BotA responds ← should not respond

Expected Behavior

After step 3, BotA should detect the thread is multi-bot and require @mention for step 4.

Fix

Move eager multibot detection before bot message gating:

// BEFORE bot gating — detect other bots from every incoming message
if in_thread && msg.author.bot && msg.author.id != bot_id {
    let key = msg.channel_id.to_string();
    let mut cache = self.multibot_threads.lock().await;
    cache.entry(key).or_insert_with(tokio::time::Instant::now);
}

// Bot message gating (unchanged)
if msg.author.bot { ... }

Zero API calls, zero fetch — just check msg.author.bot on every incoming message before any gating.

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