From 48d430bf5e9d837b5935e34d82204036142f7489 Mon Sep 17 00:00:00 2001 From: Bongjin Lee Date: Wed, 18 Feb 2026 14:35:18 +0900 Subject: [PATCH] feat: add channel-based filtering for Discord Add `allow_channels` config option to DiscordConfig that restricts bot responses to specific Discord channels. When the list is empty (default), the bot responds in all channels (backward compatible). - Add `allow_channels: list[str]` field to DiscordConfig schema - Add channel ID check in _handle_message_create after user filtering Co-Authored-By: Claude Opus 4.6 --- nanobot/channels/discord.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nanobot/channels/discord.py b/nanobot/channels/discord.py index 9a75da1e..60ca0698 100644 --- a/nanobot/channels/discord.py +++ b/nanobot/channels/discord.py @@ -53,6 +53,7 @@ class DiscordConfig(Base): enabled: bool = False token: str = "" allow_from: list[str] = Field(default_factory=list) + allow_channels: list[str] = Field(default_factory=list) # Allowed channel IDs (empty = all) intents: int = 37377 group_policy: Literal["mention", "open"] = "mention" read_receipt_emoji: str = "👀" @@ -533,6 +534,12 @@ class DiscordChannel(BaseChannel): """Check if inbound Discord message should be processed.""" if not self.is_allowed(sender_id): return False + # Channel-based filtering: only respond in allowed channels + allow_channels = self.config.allow_channels + if allow_channels: + channel_id = self._channel_key(message.channel) + if channel_id not in allow_channels: + return False if message.guild is not None and not self._should_respond_in_group(message, content): return False return True