在 python 下运行 koishi 的实例
pip install "koishi-python @ git+https://github.com/koishipy/koishi-python"from koishi import Context
ctx = Context({})
ctx.requires(
"@koishijs/plugin-console",
"@koishijs/plugin-sandbox",
"@koishijs/plugin-server",
config="koishi.yml",
)
ctx.command("echo <message:text>", "输出收到的信息", {"checkArgCount": True})\
.action(lambda _, __, *args: args[0])
ctx.run()config 指向 Koishi 配置文件。ctx.requires() 会读取其中的 plugins,并按 Koishi 的插件短名称匹配传入的 npm 包名。
# koishi.yml
plugins:
console:
sandbox:
server:
port: 5140插件组、插件别名和 ~ 禁用前缀同样按 Koishi 配置格式解析;ctx.requires() 中仍需传入待安装的 npm 包名。
ctx.requires()声明的 npm 包会先统一写入生成的package.json,再通过一次 Yarn 安装- 运行时内置
.yarn/releases/yarn-4.17.1.cjs,并在.yarnrc.yml中通过yarnPath固定使用它;用户环境只需提供 Node.js,无需安装 Yarn 或 Corepack。 - 目前默认安装 Koishi 和插件的最新版本;
ctx.require()仍可通过version指定版本。 koishi会在运行目录下建立node_modules、package.json、yarn.lock、.yarn和.yarnrc.yml的软链接;JavaScript 模块仍由 JSPyBridge 直接加载,不再生成额外入口文件。- JSPyBridge 目前仍可能输出
property r/ffid is not registered警告;该警告不影响 Koishi 启动。