Description
When multiple openab bots share a Discord guild, a role mention intended for one bot triggers all bots whose allowed_channels include that channel.
Root cause: openab supports triggering the bot via role mention (in addition to direct @user mention). The detection logic at discord.rs:53 checks if msg.mention_roles appear in msg.content via string matching:
msg.mention_roles.iter().any(|r| msg.content.contains(&format!("<@&{}>", r)))
This matches any role mentioned in the message, because the code never checks whether the mentioned roles actually belong to the receiving bot. If bot A has role X and bot B has role Y, a message mentioning role Y will incorrectly trigger bot A.
Proposed fix: compare msg.mention_roles against the bot's own guild roles instead of string-matching the message content.
Performance consideration: calling guild.member() per message to look up the bot's roles adds an API call on every message. A role cache (populated once from guild_create events and stored in a RwLock<HashSet>) eliminates this overhead entirely. guild_create is preferred over ready because ready.guilds only contains UnavailableGuild stubs — guild member data may not be available until guild_create fires, particularly for larger guilds.
Use Case
In a multi-bot guild (e.g., multiple openab agents each with their own Discord role for targeted routing), role-mentioning one agent should not trigger the others. This is critical for multi-agent architectures where different agents have different capabilities and tasks must be routed precisely.
Description
When multiple openab bots share a Discord guild, a role mention intended for one bot triggers all bots whose
allowed_channelsinclude that channel.Root cause: openab supports triggering the bot via role mention (in addition to direct @user mention). The detection logic at
discord.rs:53checks ifmsg.mention_rolesappear inmsg.contentvia string matching:This matches any role mentioned in the message, because the code never checks whether the mentioned roles actually belong to the receiving bot. If bot A has role X and bot B has role Y, a message mentioning role Y will incorrectly trigger bot A.
Proposed fix: compare
msg.mention_rolesagainst the bot's own guild roles instead of string-matching the message content.Performance consideration: calling
guild.member()per message to look up the bot's roles adds an API call on every message. A role cache (populated once fromguild_createevents and stored in aRwLock<HashSet>) eliminates this overhead entirely.guild_createis preferred overreadybecauseready.guildsonly containsUnavailableGuildstubs — guild member data may not be available untilguild_createfires, particularly for larger guilds.Use Case
In a multi-bot guild (e.g., multiple openab agents each with their own Discord role for targeted routing), role-mentioning one agent should not trigger the others. This is critical for multi-agent architectures where different agents have different capabilities and tasks must be routed precisely.