[Bug] Discord slash command sync aborts with KeyError when a plugin handler is defined in a submodule
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 77/100
Hướng nghiên cứu
Bắt đầu tại _collect_and_register_commands trong astrbot/core/platform/sources/discord/discord_platform_adapter.py, khoảng dòng 475, và so sánh cách tra cứu star_map với các cách tra cứu có kiểm tra được mô tả trong issue. Tái hiện bằng một trình xử lý plugin từ mô-đun con và bật đăng ký lệnh Discord. Hoàn thành khi trình xử lý không xác định hoặc không hoạt động bị bỏ qua và quá trình đồng bộ lệnh kết thúc mà không bị dừng giữa chừng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
Discord slash commands are never synced when any plugin registers an event handler from a submodule (for example, a mixin class defined in plugin/foo.py and inherited by the plugin's main Star class).
Such a handler is registered with handler_module_path = handler.__module__ = data.plugins.<plugin>.foo, but star_map is only keyed by the plugin's main module (data.plugins.<plugin>.main). DiscordPlatformAdapter._collect_and_register_commands (astrbot/core/platform/sources/discord/discord_platform_adapter.py:475) does a direct lookup:
if not star_map[handler_md.handler_module_path].activated:
continue
This raises KeyError inside on_ready, which aborts the loop before sync_commands() is called, so no plugin's slash commands get registered — not just the offending plugin's.
Other parts of the core already guard this lookup and skip unknown handlers (e.g. StarHandlerRegistry.get_handlers_by_event_type uses star_map.get(...), and the Telegram adapter checks handler_module_path not in star_map). The Discord adapter is the only one that crashes.
Suggested fix: use star_map.get() and skip handlers whose plugin is missing or inactive.
Reproduction Steps
- Enable a Discord platform adapter with
discord_command_register: true. - Install a plugin whose main class inherits a mixin from another module of the same plugin, where the mixin method is decorated with an event filter, e.g.:
(Real-world example:# plugin/foo.py class FooMixin: @filter.on_llm_response() async def on_resp(self, event, resp): ... # plugin/main.py from .foo import FooMixin class MyPlugin(FooMixin, Star): ...astrbot_plugin_private_companion,atrelay.py.) - Start AstrBot and wait for the Discord bot to become ready.
on_ready_once_callbackfails withKeyErrorand no slash commands are synced.
AstrBot Version
v4.29.1 (the same code is still present on current master)
Operating System
Linux
Deployment Method
Source (uv run main.py) managed by systemd
Message Platform Adapter
Discord
Error Log
[Core] [INFO] [discord.client:44]: [Discord] Logged in as <bot>
[Core] [INFO] [discord.discord_platform_adapter:471]: [Discord] Collecting and registering slash commands...
[Core] [ERRO] [v4.29.1] [discord.discord_platform_adapter:158]: [Discord] on_ready_once_callback err: 'data.plugins.astrbot_plugin_private_companion.atrelay'
Traceback (most recent call last):
File ".../discord/client.py", line 465, in _run_event
File "/opt/AstrBot/astrbot/core/platform/sources/discord/client.py", line 50, in on_ready
File "/opt/AstrBot/astrbot/core/platform/sources/discord/discord_platform_adapter.py", line 151, in callback
File "/opt/AstrBot/astrbot/core/platform/sources/discord/discord_platform_adapter.py", line 475, in _collect_and_register_commands
KeyError: 'data.plugins.astrbot_plugin_private_companion.atrelay'
After changing that line to star_map.get() locally:
[Discord] Ready to sync 49 commands: ...
[Discord] Command synchronization completed.
Supplementary Information
The plugin-side handler itself is also never invoked by the core (it is never bound to the plugin instance and is filtered out during dispatch); that part is a plugin issue and is being reported to the plugin author separately. This issue is only about the Discord adapter turning one unbound handler into a failure of the whole command sync.
Checklist
- I have searched the Issue list for related issues and could not resolve the problem, or this issue has never been reported before.
- I have tried disabling all plugins to rule out issues caused by plugins. (The trigger is a plugin's handler layout; the crash itself is in the Discord adapter, see above.)
- The issue I am reporting is related to AstrBot itself, not to a specific plugin.
- I have read and agree to the project's Code of Conduct.
- (Optional) I am willing to submit a PR to help fix this issue.
- Ngôn ngữ chính
- Python
- Star
- 42.1k
- Fork
- 3.1k
- Merge trung bình
- 1 ngày 50 phút
- Pull request đã merge (30 ngày)
- 146
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AstrBotDevs/AstrBot
-
[Bug] Default PyPI mirror disables TLS certificate verification for plugin dependenciesCó thể đã có người làm @DOTBave đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AstrBotDevs/AstrBot#10684 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] 现实世界时间感知文案需要更新Có thể đã có người làm @mantoujun12 đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
AstrBotDevs/AstrBot#10682 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频Có thể đã có người làm @he-yufeng đã nhận 15 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
AstrBotDevs/AstrBot#10420 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Feature] 移除「切换到旧版知识库」入口Có thể đã có người làm @lingyun14beta đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AstrBotDevs/AstrBot#10340 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
AstrBotDevs/AstrBot#10322 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của AstrBotDevs/AstrBot
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
aws-samples/sample-per-model-bedrock#464 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
lesson-submission pending-review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Ikalus1988/MisakaNet#3789 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Python Volcengine provider returns failures instead of raising themCó thể đã có người làm @Ricardo-M-L đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
agent-infra/sandbox#248 ·
-
[Bug] cloud JSON directory loading assumes a Key field in fsspec listingsCó thể đã có người làm @Ricardo-M-L đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
hiyouga/LlamaFactory#10910 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bundled uv is never updated and trusts the compromised eMudhra certificatesCó thể đã có người làm @FabienDanieau đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100