Skip to content

Commit bd1935c

Browse files
committed
fix
1 parent b3fb3af commit bd1935c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

dev/plugin.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ async def my_custom_hook_1(self, event: AstrMessageEvent, req: ProviderRequest):
361361

362362
```
363363

364+
> 这里不能使用 yield 来发送消息。如需发送,请直接使用 `event.send()` 方法。
365+
364366
#### LLM 请求完成时
365367

366368
在 LLM 请求完成后,会触发 `on_llm_response` 钩子。
@@ -373,7 +375,9 @@ from astrbot.api.provider import LLMResponse
373375
@filter.on_llm_response()
374376
async def on_llm_resp(self, event: AstrMessageEvent, resp: LLMResponse): # 请注意有三个参数
375377
print(resp)
376-
```
378+
```
379+
380+
> 这里不能使用 yield 来发送消息。如需发送,请直接使用 `event.send()` 方法。
377381
378382
#### 发送消息给消息平台适配器前
379383

@@ -384,9 +388,14 @@ async def on_llm_resp(self, event: AstrMessageEvent, resp: LLMResponse): # 请
384388
```python
385389
@filter.on_decorating_result()
386390
async def on_decorating_result(self, event: AstrMessageEvent):
387-
print(event.get_result()) # 打印消息链
391+
result = event.get_result()
392+
chain = result.chain
393+
print(chain) # 打印消息链
394+
chain.append(Plain("!")) # 在消息链的最后添加一个感叹号
388395
```
389396

397+
> 这里不能使用 yield 来发送消息。这个钩子只是用来装饰 event.get_result().chain 的。如需发送,请直接使用 `event.send()` 方法。
398+
390399
#### 发送消息给消息平台适配器后
391400

392401
在发送消息给消息平台后,会触发 `after_message_sent` 钩子。
@@ -397,6 +406,8 @@ async def after_message_sent(self, event: AstrMessageEvent):
397406
pass
398407
```
399408

409+
> 这里不能使用 yield 来发送消息。如需发送,请直接使用 `event.send()` 方法。
410+
400411
### 优先级
401412

402413
> 大于等于 v3.4.21 版本才有这个功能,低于这个版本的 AstrBot 会报错。

0 commit comments

Comments
 (0)