Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(discord): stop outbound messages from pinging everyone and roles

Lanre Shittud250bc7a4e6b
diff --git a/agent/src/channels/discord.py b/agent/src/channels/discord.py
index 1bbc3632d..2c4bbd23d 100644
--- a/agent/src/channels/discord.py
+++ b/agent/src/channels/discord.py
@@ -78,7 +78,16 @@ if DISCORD_AVAILABLE:
proxy: str | None = None,
proxy_auth: aiohttp.BasicAuth | None = None,
) -> None:
- super().__init__(intents=intents, proxy=proxy, proxy_auth=proxy_auth)
+ # Applies to every channel.send()/edit() that doesn't pass its own
+ # allowed_mentions (streaming edits, overflow chunks, etc.) -- without
+ # it, a literal @everyone/@here or role mention in outbound text
+ # (e.g. echoed back from an LLM response) actually pings.
+ super().__init__(
+ intents=intents,
+ proxy=proxy,
+ proxy_auth=proxy_auth,
+ allowed_mentions=discord.AllowedMentions(everyone=False, roles=False),
+ )
self._channel = channel
self.tree = app_commands.CommandTree(self)
self._register_app_commands()
@@ -324,7 +333,12 @@ if DISCORD_AVAILABLE:
reply_to: str | None,
) -> tuple[discord.PartialMessage | None, discord.AllowedMentions]:
"""Build reply context for outbound messages."""
- mention_settings = discord.AllowedMentions(replied_user=False)
+ # An explicit allowed_mentions kwarg overrides the client-level
+ # default, so this must suppress everyone/roles too, not just
+ # the reply ping.
+ mention_settings = discord.AllowedMentions(
+ everyone=False, roles=False, replied_user=False
+ )
if not reply_to:
return None, mention_settings
try:
diff --git a/agent/tests/test_discord_allowed_mentions.py b/agent/tests/test_discord_allowed_mentions.py
new file mode 100644
index 000000000..3cb55b6f9
--- /dev/null
+++ b/agent/tests/test_discord_allowed_mentions.py
@@ -0,0 +1,41 @@
+"""Regression: outbound Discord sends must not let literal @everyone/@here or
+role-mention tokens actually ping.
+
+discord.AllowedMentions(replied_user=False) leaves everyone/users/roles at
+their True default, so a bare "@everyone" in outbound text (e.g. echoed back
+from an LLM response) pinged the whole server on every send path -- both the
+explicit reply/file paths and the plain channel.send() calls (streaming
+edits, overflow chunks) that pass no allowed_mentions at all and so fell
+back to Discord's own parse-from-content default.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+discord = pytest.importorskip("discord")
+
+from src.channels.discord import DiscordBotClient # noqa: E402
+
+
+class _FakeChannel:
+ logger = None
+
+
+def _client() -> DiscordBotClient:
+ return DiscordBotClient(_FakeChannel(), intents=discord.Intents.none())
+
+
+def test_client_level_default_suppresses_everyone_and_roles():
+ client = _client()
+ assert client.allowed_mentions is not None
+ assert client.allowed_mentions.everyone is False
+ assert client.allowed_mentions.roles is False
+
+
+def test_reply_context_mention_settings_suppress_everyone_and_roles():
+ client = _client()
+ _, mention_settings = client._build_reply_context(channel=None, reply_to=None)
+ assert mention_settings.everyone is False
+ assert mention_settings.roles is False
+ assert mention_settings.replied_user is False