Skip to content

事件 (Events)

nonebot-adapter-yunhu 负责接收来自云湖平台的 Webhook 事件。

本页将详细说明云湖事件与 Nonebot 事件之间的对应关系。

您可以在插件中通过依赖注入来监听这些事件。

TIP

监听响应器的使用请参考 Nonebot 文档,这里只是一种极其简单的示范

例如:

python
#  监听通知事件
matcher = on_notice()

@matcher.handle()
async def _(event: GroupJoinNoticeEvent): # 仅监听新成员加入群聊
    await matcher.send(MessageSegment.markdown(f"> ![image]({event.event.avatarUrl})\n\n`{event.event.nickname}` 加入了我们..."))

# 监听消息事件
aya = on_message()
@aya.handle()
async def _(event: MessageEvent): # 任意消息均会触发此响应器
  ...

com = on_command("aya", block=True, priority=5)
@com.handle()
async def _(event: InstructionMessageEvent): # 仅斜线指令会触发
  ...



ovo = on_command("ovo", block=True, priority=5)
@com.handle()
async def _(event: GroupMessageEvent): # 仅群消息会触发
  ...
## 不建议这样监听群消息,可以使用rule来过滤群消息

消息事件 (MessageEvent)

云湖事件类型Nonebot 事件Nonebot 事件类触发时机
message.receive.normalmessage.receive.normal.groupGroupMessageEvent收到群组消息
message.receive.normalmessage.receive.normal.botPrivateMessageEvent收到私聊消息
message.receive.instructionmessage.receive.instructionInstructionMessageEvent用户触发了机器人的斜线指令

通知事件 (NoticeEvent)

云湖事件类型Nonebot 事件Nonebot 事件类触发时机
message.receive.normalgroup.tipTipNoticeEvent群成员被设置为管理员
bot.followedbot.followedBotFollowedNoticeEvent用户添加机器人到通讯录
bot.unfollowedbot.unfollowedBotUnfollowedNoticeEvent用户从通讯录删除机器人
group.joingroup.joinGroupJoinNoticeEvent新成员加入群组
group.leavegroup.leaveGroupLeaveNoticeEvent成员退出群组
button.report.inlinebutton.report.inlineButtonReportNoticeEvent用户点击了消息中的内联按钮

关于指令消息

指令消息会自动拼接可能的参数

例如

  1. 后台配置指令消息为 每日发癫
  2. 客户端显示为 /每日发癫
  3. 用户选中指令并输入参数 Feng
  4. 后台收到消息为 每日发癫 Feng
  5. 实际效果与用户直接发送 每日发癫 Feng 相同,指令消息只是让用户不用打指令了