AstrBot Plugin Runtime Patching
Patch a running AstrBot's plugins without rebuilding the bot. This skill is for when an installed plugin behaves wrong despite correct config and the user wants a quick in-place fix (not a full reinstall).
When to use
- User says "插件 X 不工作了 / 报错了 / 一直说不可用" with logs pointing
to
astrbot_plugin_<name>. - User reports a plugin shows wrong version in the marketplace but the upstream repo has moved on (fork drift).
- User's plugin command parses its
args_strwrong when invoked via QQ reply.
When NOT to use
- The bot itself fails to start (
astrbotwon't come up) — that's an AstrBot core / config problem, not a plugin problem. - The plugin was never installed — go through AstrBot's plugin market first.
- The user wants to publish a fix upstream — that's
astrbot-plugin-development; this skill is for local hot-fix only.
Triage workflow
Localise the failure:
tail -F /home/po/astrbot/data/logs/astrbot.log(rotated siblingsastrbot.YYYY-MM-DD_HH-MM-SS_xxxxxx.log). Grep for the plugin name and forERROR/Traceback. The log line that names a strategy / command / config key is the one to read.Read the plugin source:
/home/po/astrbot/data/plugins/<name>/.main.pyis the entry. Each provider / strategy lives in its own file (sauce_nao_strategy.py, etc.).metadata.yamlhas the version the bot believes is installed._conf_schema.jsonlists config keys.Read AstrBot's message adapter when a command parses wrong:
/home/po/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py. This is whereevent.message_stris built. If your command handler sees "message_str contains quoted-message noise", the bug is in your plugin's parser, not in AstrBot (see references below).Patch in place. Use
search_filesto find the right line range beforepatch. Don't rewrite the file from scratch — one guard in the shared resolver is smaller diff than guards in every caller.Reload, do not full restart. WebUI 插件页 → 重载 is enough for pure-Python changes. Only
sudo systemctl restart astrbotif the patch changedmetadata.yaml(AstrBot reads it on startup) or dependencies (requirements.txt).Verify. Re-trigger the failing command once and grep the log for the previous error string — if absent, patch landed.
Pitfalls
Plugin version is cached in
data/plugins.json(anddata/plugins_custom_<md5>.jsonfor custom registries). The market shows the cached version until MD5 mismatches. Restart does not force refresh; the MD5 endpoint ishttps://api.soulter.top/astrbot/plugins-md5. When upstream is forked and the new owner hasn't pushed toAstrBotDevs/AstrBot_Plugins_Collection, the cache stays stale forever. Workaround:rm -rfthe plugin dir andgit clonethe new repo, then reload.metadata.yamlhas noastrbot_versionconstraint check at runtime (it's only a market-metadata hint). Patches that depend on new AstrBot core APIs need a version check you write yourself.pip install -r requirements.txtafter a plugin update will trigger pip 26.3 deprecation warnings if the plugin importsdata.plugins.<x>in an order pip doesn't expect. Safe to ignore until pip 26.3 actually enforces it. Do not "fix" by changing import paths — that breaks AstrBot's plugin loader.Fork reinstalls wipe any in-place patch you made to
main.py. If you patch and the user later upgrades, re-apply or upstream the fix. Markponytail:comments so future-you knows what was local.
References
references/onebot-reply-messagestr-pollution.md— exact bug pattern for QQ reply-mode command parsing, with therfind+ whitelist filter fix. Read this when the log shows未找到策略 '图片 MSG_ID:....references/plugin-market-cache-fork-staleness.md— when plugin market stays on old version after the upstream has moved.