fix(discord): allow bot-to-bot messaging, only drop self-loops (#3217)

Previously the Discord channel dropped every message from any bot
account via `if message.author.bot`, which prevented legitimate
multi-agent setups (one bot asking another for help, bot-to-bot
@mentions, etc.) from working.

Narrow the guard to only drop messages from this bot's own account
by comparing against self._bot_user_id (already populated in on_ready).
Self-loop protection is preserved — each bot instance still ignores
its own outbound messages.

Co-authored with Claude Opus 4.7
This commit is contained in:
Alfredo Arenas 2026-04-18 07:15:38 -06:00 committed by Xubin Ren
parent 7527961b19
commit 3fd24c72fd

View File

@ -433,8 +433,15 @@ class DiscordChannel(BaseChannel):
raise raise
async def _handle_discord_message(self, message: discord.Message) -> None: async def _handle_discord_message(self, message: discord.Message) -> None:
"""Handle incoming Discord messages from discord.py.""" """Handle incoming Discord messages from discord.py.
if message.author.bot:
Self-loop guard: only drop messages from this bot's own account. Messages
from other bots are allowed through so multi-agent setups (one bot asking
another for help, a bot mentioning another by @name, etc.) can work.
Bot-from-bot loops are still prevented per-instance because each bot
still ignores its own outbound messages. (#3217)
"""
if self._bot_user_id is not None and str(message.author.id) == self._bot_user_id:
return return
sender_id = str(message.author.id) sender_id = str(message.author.id)