← 返回
未分类 中文

AstrBot plugin dev skill

Guide for developing AstrBot plugins that match the AstrBot main repo, pass astr-plugin-reviewer checks, and cover commands, filters, hooks, LLM integrations...
AstrBot 插件开发指南,要求与 AstrBot 主仓库保持一致,通过 astr-plugin-reviewer 检查,涵盖指令、过滤器、钩子、LLM 集成等。
camera-2018
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 359
下载
💾 0
安装
1
版本
#latest

概述

AstrBot Plugin Development

Use this skill to write AstrBot plugins in a reviewer-first way: align with astr-plugin-reviewer hard checks, then follow the current AstrBot repository APIs and docs.

Start Here

Before writing code, always read these two references first:

Then load only the references you need:

Default Workflow

  1. Create or verify main.py and metadata.yaml first.
  2. Treat metadata.yaml as the source of truth for plugin identity. Prefer desc plus repo, and never keep both desc and description.
  3. In main.py, define a class that inherits Star. Prefer AstrBot's auto-discovery; do not introduce the deprecated @register decorator unless you are maintaining old code.
  4. Import filter exactly with from astrbot.api.event import filter to avoid reviewer failures and naming confusion.
  5. Import the logger exactly with from astrbot.api import logger.
  6. Keep network I/O async. Prefer httpx or aiohttp; do not use requests, blocking sleeps, or other blocking network calls.
  7. If the plugin needs persistent files, prefer StarTools.get_data_dir(). It returns a Path.
  8. If you implement LLM hooks, LLM tools, direct LLM calls, or agents, follow the exact signatures and restrictions in references/advanced-features.md.
  9. Before finishing, run a self-check against references/reviewer-checklist.md. If the user wants marketplace publishing, also ensure the publish JSON matches metadata.yaml exactly.

Minimal Template

from pathlib import Path

from astrbot.api import logger
from astrbot.api.event import AstrMessageEvent, filter
from astrbot.api.star import Context, Star, StarTools


class MyPlugin(Star):
    def __init__(self, context: Context):
        super().__init__(context)
        self.data_dir: Path = StarTools.get_data_dir()

    @filter.command("helloworld")
    async def helloworld(self, event: AstrMessageEvent):
        """回复一个简单问候。"""
        logger.info(f"helloworld triggered by {event.get_sender_id()}")
        yield event.plain_result(f"Hello, {event.get_sender_name()}!")

    async def terminate(self):
        """Called when the plugin is unloaded or disabled."""

Note: The @register decorator is deprecated in newer versions of AstrBot. Please use metadata.yaml to define plugin metadata. AstrBot automatically detects the plugin class inheriting from Star.

Core Workflows

1. Project Setup and Metadata

A complete plugin requires metadata.yaml for identification, requirements.txt for dependencies, and optionally logo.png, _conf_schema.json, and a README.md.

  • Plugin names should start with astrbot_plugin_, be lowercase, have no spaces, and be short.
  • See references/project-structure.md for mandatory files, dev environment setup, and publishing.

2. Registering Commands and Filters

Commands are registered using @filter.command(name). AstrBot auto-parses command parameters by type hints. You can also use command groups, command aliases, and filter by event type, platform, or user permission.

  • See references/core-api.md for full list of filters, hooks, the platform compatibility matrix, and event propagation control.

3. Handling Messages and Responses

AstrBot uses a message-chain system. You can respond with plain text, images, or a mix of components. Proactive messages are supported via unified_msg_origin and MessageChain.

4. Advanced Integrations

  • Configuration: Use _conf_schema.json for user settings.
  • LLM Tools: Register tools via @filter.llm_tool or FunctionTool.
  • LLM Direct Calls: Use self.context.llm_generate() to call LLMs directly.
  • Agent / Multi-Agent: Use self.context.tool_loop_agent() for tool-loop agents.
  • Stateful Interaction: Use session_waiter for multi-step prompts with custom session filters.
  • T2I: Render text or HTML/Jinja2 templates to images.
  • Conversation & Persona Managers: Access LLM conversation history and persona settings when needed.

See references/advanced-features.md for examples.

Elegant Design Patterns

Follow these patterns for robust, user-friendly plugins:

  • Use unified logging via from astrbot.api import logger.
  • Handle errors gracefully to avoid bot crashes.
  • Use KV storage or the plugin data directory for persistence.
  • Ensure all I/O operations are non-blocking.
  • Access platform instances, loaded plugins, and protocol-level APIs only when necessary.

See references/patterns.md for detailed code patterns.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 12:56 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 80 📥 182,947
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 42,073
dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 198 📥 68,175