[Bug] Discord slash command sync aborts with KeyError when a plugin handler is defined in a submodule
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 77/100
Línea de trabajo
Empieza en _collect_and_register_commands en astrbot/core/platform/sources/discord/discord_platform_adapter.py, alrededor de la línea 475, y compara la búsqueda en star_map con las búsquedas protegidas descritas en el issue. Reproduce el problema con un handler de plugin de un submódulo y el registro de comandos de Discord habilitado. Se considera terminado cuando se omite un handler desconocido o inactivo y la sincronización de comandos finaliza sin abortar.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 42.1k
- Forks
- 3.1k
- Merge medio
- 1 d 50 min
- PR fusionados (30 d)
- 146
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de AstrBotDevs/AstrBot
-
[Bug] Default PyPI mirror disables TLS certificate verification for plugin dependenciesPosiblemente ocupada @DOTBave la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AstrBotDevs/AstrBot#10684 ·
Los mantenedores suelen responder en 1 día
-
[Bug] 现实世界时间感知文案需要更新Posiblemente ocupada @mantoujun12 la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
AstrBotDevs/AstrBot#10682 ·
Los mantenedores suelen responder en 1 día
-
[Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频Posiblemente ocupada @he-yufeng la tomó hace 15 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
AstrBotDevs/AstrBot#10420 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Feature] 移除「切换到旧版知识库」入口Posiblemente ocupada @lingyun14beta la tomó hace 12 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AstrBotDevs/AstrBot#10340 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
AstrBotDevs/AstrBot#10322 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de AstrBotDevs/AstrBot
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
foxglove/mcap#1907 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
namespace operations
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
EclipseFdn/open-vsx.org#14623 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
developmentseed/titiler-cmr#261 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
andrewyng/openworker#774 ·
Los mantenedores suelen responder en 1 día
-
aggfuncAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
worldbank/blackmarblepy#160 ·