feat(discord): add configurable bot message filtering#6505
feat(discord): add configurable bot message filtering#6505MinaraAgent wants to merge 4 commits intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, 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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 onDiscordBotClientso the option is discoverable and checked by static analysis. - In
on_message, you might early-return even faster by checkingif 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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.
astrbot/core/platform/sources/discord/discord_platform_adapter.py
Outdated
Show resolved
Hide resolved
MinaraAgent
left a comment
There was a problem hiding this comment.
Thank you for the review feedback! I've addressed all the suggestions:
- ✅ Added
allow_bot_messagesas a typed constructor argument inDiscordBotClient - ✅ Simplified the
on_messagecheck to useself.allow_bot_messagesdirectly - ✅ Updated the adapter to pass the parameter in constructor instead of using
setattr
All changes have been pushed in commit aeff159.
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>
aeff159 to
fe0cbce
Compare
Summary
discord_allow_bot_messagesconfig option to allow receiving messages from other Discord botsUsage
Set
discord_allow_bot_messages: truein your Discord platform configuration.Changes
client.py: Modifiedon_messageto checkallow_bot_messagesattribute before filtering bot messagesdiscord_platform_adapter.py: Readdiscord_allow_bot_messagesfrom config and set it on the clientTest Plan
discord_allow_bot_messages: false(default) - bot messages should be ignoreddiscord_allow_bot_messages: true- bot messages should be received🤖 Generated with Claude Code
Summary by Sourcery
New Features: