Files
AstrBot/docs/en/dev/star/guides/storage.md
2doright 574e5089ba docs: fix path concatenation error in storage.md (#7448)
* docs: 修复 storage.md 中路径拼接的错误示例

get_astrbot_data_path() 返回的是 str 类型,直接使用 / 运算符会导致 TypeError。修改文档示例,添加 Path() 包裹

* docs: 修复 storage.md 中路径拼接的错误示例

get_astrbot_data_path() 返回的是 str 类型,直接使用 / 运算符会导致 TypeError。修改文档示例,添加 Path() 包裹。
2026-04-10 18:41:54 +08:00

1.0 KiB

Plugin Storage

Simple KV Storage

Tip

Requires AstrBot version >= 4.9.2.

Plugins can use AstrBot's simple key-value store to persist configuration or temporary data. The storage is scoped per plugin, so each plugin has its own isolated space.

class Main(star.Star):
    @filter.command("hello")
    async def hello(self, event: AstrMessageEvent):
        """Aloha!"""
        await self.put_kv_data("greeted", True)
        greeted = await self.get_kv_data("greeted", False)
        await self.delete_kv_data("greeted")

Large File Storage Convention

To keep large file handling consistent, store large files under data/plugin_data/{plugin_name}/.

You can fetch the plugin data directory with:

from pathlib import Path
from astrbot.core.utils.astrbot_path import get_astrbot_data_path

plugin_data_path = Path(get_astrbot_data_path()) / "plugin_data" / self.name  # self.name is the plugin name; available in v4.9.2 and above. For lower versions, specify the plugin name yourself.