Skip to content

feat(discord): add configurable bot message filtering#6505

Open
MinaraAgent wants to merge 4 commits intoAstrBotDevs:masterfrom
MinaraAgent:feature/discord-allow-bot-messages
Open

feat(discord): add configurable bot message filtering#6505
MinaraAgent wants to merge 4 commits intoAstrBotDevs:masterfrom
MinaraAgent:feature/discord-allow-bot-messages

Conversation

@MinaraAgent
Copy link
Copy Markdown

@MinaraAgent MinaraAgent commented Mar 17, 2026

Summary

  • Add discord_allow_bot_messages config option to allow receiving messages from other Discord bots
  • This enables bot-to-bot communication scenarios (e.g., message forwarding between channels)
  • Backward compatible: bot messages are still ignored by default

Usage

Set discord_allow_bot_messages: true in your Discord platform configuration.

Changes

  • client.py: Modified on_message to check allow_bot_messages attribute before filtering bot messages
  • discord_platform_adapter.py: Read discord_allow_bot_messages from config and set it on the client

Test Plan

  • Test with discord_allow_bot_messages: false (default) - bot messages should be ignored
  • Test with discord_allow_bot_messages: true - bot messages should be received
  • Verify no regression in normal user message handling

🤖 Generated with Claude Code

Summary by Sourcery

New Features:

  • Introduce a Discord configuration option to enable receiving messages from other bot accounts.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 17, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Discord platform integration by providing a new configuration option to allow or disallow the processing of messages originating from other Discord bots. This change facilitates more complex bot interactions and communication patterns while maintaining backward compatibility by keeping the default behavior of ignoring bot messages.

Highlights

  • Configurable Bot Message Filtering: Introduced a new configuration option, discord_allow_bot_messages, to control whether the bot processes messages from other Discord bots.
  • Bot-to-Bot Communication: This feature enables scenarios requiring interaction between bots, such as message forwarding between channels.
  • Backward Compatibility: The default behavior remains unchanged; bot messages are ignored unless explicitly enabled, ensuring no disruption to existing setups.
Changelog
  • astrbot/core/platform/sources/discord/client.py
    • Updated the on_message handler to conditionally filter messages from bots based on the new allow_bot_messages attribute.
  • astrbot/core/platform/sources/discord/discord_platform_adapter.py
    • Modified the adapter to read the discord_allow_bot_messages setting from the configuration and apply it to the Discord client instance.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Instead of using setattr(self.client, "allow_bot_messages", allow_bot_messages), consider adding a typed attribute or constructor argument on DiscordBotClient so the option is discoverable and checked by static analysis.
  • In on_message, you might early-return even faster by checking if message.author.bot and not getattr(self, "allow_bot_messages", False): directly, avoiding the extra local and keeping the logic compact.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of using `setattr(self.client, "allow_bot_messages", allow_bot_messages)`, consider adding a typed attribute or constructor argument on `DiscordBotClient` so the option is discoverable and checked by static analysis.
- In `on_message`, you might early-return even faster by checking `if message.author.bot and not getattr(self, "allow_bot_messages", False):` directly, avoiding the extra local and keeping the logic compact.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Mar 17, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new configuration option discord_allow_bot_messages to control whether messages from other bots are processed. The implementation is correct and maintains backward compatibility. My review includes suggestions to improve code quality by making the new configuration an explicit parameter in the DiscordBotClient constructor, rather than setting it dynamically. This will enhance code clarity and maintainability.

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Mar 17, 2026
Copy link
Copy Markdown
Author

@MinaraAgent MinaraAgent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review feedback! I've addressed all the suggestions:

  1. ✅ Added allow_bot_messages as a typed constructor argument in DiscordBotClient
  2. ✅ Simplified the on_message check to use self.allow_bot_messages directly
  3. ✅ Updated the adapter to pass the parameter in constructor instead of using setattr

All changes have been pushed in commit aeff159.

MinaraAgent and others added 3 commits March 23, 2026 04:05
Add `discord_allow_bot_messages` config option to allow receiving
messages from other Discord bots. This is useful for bot-to-bot
communication scenarios like message forwarding between channels.

By default, bot messages are still ignored (backward compatible).

Usage: Set `discord_allow_bot_messages: true` in your Discord
platform configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add configuration option to the dashboard for the new
discord_allow_bot_messages feature. Users can now enable/disable
this option through the WebUI in all supported languages
(zh-CN, en-US, ru-RU).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address code review feedback:
- Add `allow_bot_messages` as a typed constructor argument in DiscordBotClient
- Simplify the on_message check by using the instance attribute directly
- Pass the parameter in constructor instead of using setattr

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MinaraAgent MinaraAgent force-pushed the feature/discord-allow-bot-messages branch from aeff159 to fe0cbce Compare March 23, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants