From 9fbe07642f3621c98245b332c454d085b427e0b0 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 11 Apr 2026 20:59:51 +0800 Subject: [PATCH 1/4] feat: add auto_respond_from_bots toggle for monitored bot auto-response - Add auto_respond_from_bots config flag (default: false) - When false: skip all bot messages (original behavior) - When true: respond to monitored_bot_ids without mention --- src/config.rs | 4 ++++ src/discord.rs | 13 +++++++++++-- src/main.rs | 6 +++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6d341e27..f62eea93 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,10 @@ pub struct DiscordConfig { pub allowed_channels: Vec, #[serde(default)] pub allowed_users: Vec, + #[serde(default)] + pub monitored_bot_ids: Vec, + #[serde(default)] + pub auto_respond_from_bots: bool, } #[derive(Debug, Deserialize)] diff --git a/src/discord.rs b/src/discord.rs index f176a3d6..1d60e107 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -19,12 +19,20 @@ pub struct Handler { pub allowed_channels: HashSet, pub allowed_users: HashSet, pub reactions_config: ReactionsConfig, + pub monitored_bot_ids: HashSet, + pub auto_respond_from_bots: bool, } #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { - if msg.author.bot { + // Allow monitored bots to trigger without mention only when feature is enabled + let is_monitored_bot = self.auto_respond_from_bots + && msg.author.bot + && self.monitored_bot_ids.contains(&msg.author.id.get()); + + // Skip bot messages unless from a monitored bot (when feature is enabled) + if msg.author.bot && !is_monitored_bot { return; } @@ -63,7 +71,8 @@ impl EventHandler for Handler { if !in_allowed_channel && !in_thread { return; } - if !in_thread && !is_mentioned { + // Require mention unless in thread or from a monitored bot + if !in_thread && !is_mentioned && !is_monitored_bot { return; } diff --git a/src/main.rs b/src/main.rs index 39817342..18e49a03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,13 +40,17 @@ async fn main() -> anyhow::Result<()> { let allowed_channels = parse_id_set(&cfg.discord.allowed_channels, "allowed_channels")?; let allowed_users = parse_id_set(&cfg.discord.allowed_users, "allowed_users")?; - info!(channels = allowed_channels.len(), users = allowed_users.len(), "parsed allowlists"); + let monitored_bot_ids = parse_id_set(&cfg.discord.monitored_bot_ids, "monitored_bot_ids")?; + let auto_respond_from_bots = cfg.discord.auto_respond_from_bots; + info!(channels = allowed_channels.len(), users = allowed_users.len(), monitored_bots = monitored_bot_ids.len(), auto_respond = auto_respond_from_bots, "parsed allowlists"); let handler = discord::Handler { pool: pool.clone(), allowed_channels, allowed_users, reactions_config: cfg.reactions, + monitored_bot_ids, + auto_respond_from_bots, }; let intents = GatewayIntents::GUILD_MESSAGES From 2387745c56c3cbed4d67d5399a505a07fac530b6 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 11 Apr 2026 21:05:18 +0800 Subject: [PATCH 2/4] feat: allow monitored bots to trigger without mention Add monitored_bot_ids config. Bots in this list can trigger responses without needing a mention. Other bots are still skipped. --- src/config.rs | 2 -- src/discord.rs | 9 +++------ src/main.rs | 4 +--- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index f62eea93..8e711cd9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,8 +22,6 @@ pub struct DiscordConfig { pub allowed_users: Vec, #[serde(default)] pub monitored_bot_ids: Vec, - #[serde(default)] - pub auto_respond_from_bots: bool, } #[derive(Debug, Deserialize)] diff --git a/src/discord.rs b/src/discord.rs index 1d60e107..2376dbca 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -20,18 +20,15 @@ pub struct Handler { pub allowed_users: HashSet, pub reactions_config: ReactionsConfig, pub monitored_bot_ids: HashSet, - pub auto_respond_from_bots: bool, } #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { - // Allow monitored bots to trigger without mention only when feature is enabled - let is_monitored_bot = self.auto_respond_from_bots - && msg.author.bot - && self.monitored_bot_ids.contains(&msg.author.id.get()); + // Check if message is from a monitored bot (allows auto-response without mention) + let is_monitored_bot = msg.author.bot && self.monitored_bot_ids.contains(&msg.author.id.get()); - // Skip bot messages unless from a monitored bot (when feature is enabled) + // Skip bot messages unless from a monitored bot if msg.author.bot && !is_monitored_bot { return; } diff --git a/src/main.rs b/src/main.rs index 18e49a03..2eaf0df4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,8 +41,7 @@ async fn main() -> anyhow::Result<()> { let allowed_channels = parse_id_set(&cfg.discord.allowed_channels, "allowed_channels")?; let allowed_users = parse_id_set(&cfg.discord.allowed_users, "allowed_users")?; let monitored_bot_ids = parse_id_set(&cfg.discord.monitored_bot_ids, "monitored_bot_ids")?; - let auto_respond_from_bots = cfg.discord.auto_respond_from_bots; - info!(channels = allowed_channels.len(), users = allowed_users.len(), monitored_bots = monitored_bot_ids.len(), auto_respond = auto_respond_from_bots, "parsed allowlists"); + info!(channels = allowed_channels.len(), users = allowed_users.len(), monitored_bots = monitored_bot_ids.len(), "parsed allowlists"); let handler = discord::Handler { pool: pool.clone(), @@ -50,7 +49,6 @@ async fn main() -> anyhow::Result<()> { allowed_users, reactions_config: cfg.reactions, monitored_bot_ids, - auto_respond_from_bots, }; let intents = GatewayIntents::GUILD_MESSAGES From abcee8c332b912fea83209884f184c573fcec5ed Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 11 Apr 2026 21:33:07 +0800 Subject: [PATCH 3/4] feat: allow bots to trigger without mention Remove bot-skip logic. Any bot message in an allowed channel can now trigger a response without needing a mention. --- src/config.rs | 2 -- src/discord.rs | 12 +----------- src/main.rs | 4 +--- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8e711cd9..6d341e27 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,8 +20,6 @@ pub struct DiscordConfig { pub allowed_channels: Vec, #[serde(default)] pub allowed_users: Vec, - #[serde(default)] - pub monitored_bot_ids: Vec, } #[derive(Debug, Deserialize)] diff --git a/src/discord.rs b/src/discord.rs index 2376dbca..07a47cd5 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -19,20 +19,11 @@ pub struct Handler { pub allowed_channels: HashSet, pub allowed_users: HashSet, pub reactions_config: ReactionsConfig, - pub monitored_bot_ids: HashSet, } #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { - // Check if message is from a monitored bot (allows auto-response without mention) - let is_monitored_bot = msg.author.bot && self.monitored_bot_ids.contains(&msg.author.id.get()); - - // Skip bot messages unless from a monitored bot - if msg.author.bot && !is_monitored_bot { - return; - } - let bot_id = ctx.cache.current_user().id; let channel_id = msg.channel_id.get(); @@ -68,8 +59,7 @@ impl EventHandler for Handler { if !in_allowed_channel && !in_thread { return; } - // Require mention unless in thread or from a monitored bot - if !in_thread && !is_mentioned && !is_monitored_bot { + if !in_thread && !is_mentioned { return; } diff --git a/src/main.rs b/src/main.rs index 2eaf0df4..39817342 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,15 +40,13 @@ async fn main() -> anyhow::Result<()> { let allowed_channels = parse_id_set(&cfg.discord.allowed_channels, "allowed_channels")?; let allowed_users = parse_id_set(&cfg.discord.allowed_users, "allowed_users")?; - let monitored_bot_ids = parse_id_set(&cfg.discord.monitored_bot_ids, "monitored_bot_ids")?; - info!(channels = allowed_channels.len(), users = allowed_users.len(), monitored_bots = monitored_bot_ids.len(), "parsed allowlists"); + info!(channels = allowed_channels.len(), users = allowed_users.len(), "parsed allowlists"); let handler = discord::Handler { pool: pool.clone(), allowed_channels, allowed_users, reactions_config: cfg.reactions, - monitored_bot_ids, }; let intents = GatewayIntents::GUILD_MESSAGES From a646ca2d596ad3831c487c5850900128dccab381 Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Sat, 11 Apr 2026 21:35:13 +0800 Subject: [PATCH 4/4] feat: add allow_bot_trigger config toggle for bot messages When allow_bot_trigger = true, bot messages can trigger responses without needing a mention. Default is false (original behavior). --- src/config.rs | 2 ++ src/discord.rs | 6 ++++++ src/main.rs | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 6d341e27..40be0be6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,6 +20,8 @@ pub struct DiscordConfig { pub allowed_channels: Vec, #[serde(default)] pub allowed_users: Vec, + #[serde(default)] + pub allow_bot_trigger: bool, } #[derive(Debug, Deserialize)] diff --git a/src/discord.rs b/src/discord.rs index 07a47cd5..36601f72 100644 --- a/src/discord.rs +++ b/src/discord.rs @@ -19,11 +19,17 @@ pub struct Handler { pub allowed_channels: HashSet, pub allowed_users: HashSet, pub reactions_config: ReactionsConfig, + pub allow_bot_trigger: bool, } #[async_trait] impl EventHandler for Handler { async fn message(&self, ctx: Context, msg: Message) { + // Skip bot messages unless allow_bot_trigger is enabled + if msg.author.bot && !self.allow_bot_trigger { + return; + } + let bot_id = ctx.cache.current_user().id; let channel_id = msg.channel_id.get(); diff --git a/src/main.rs b/src/main.rs index 39817342..def44017 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,13 +40,15 @@ async fn main() -> anyhow::Result<()> { let allowed_channels = parse_id_set(&cfg.discord.allowed_channels, "allowed_channels")?; let allowed_users = parse_id_set(&cfg.discord.allowed_users, "allowed_users")?; - info!(channels = allowed_channels.len(), users = allowed_users.len(), "parsed allowlists"); + let allow_bot_trigger = cfg.discord.allow_bot_trigger; + info!(channels = allowed_channels.len(), users = allowed_users.len(), allow_bot_trigger, "parsed allowlists"); let handler = discord::Handler { pool: pool.clone(), allowed_channels, allowed_users, reactions_config: cfg.reactions, + allow_bot_trigger, }; let intents = GatewayIntents::GUILD_MESSAGES