参考:https://v2.nonebot.dev/api/plugin.html
- GroupDecreaseNoticeEvent:群成员减少事件
- GroupIncreaseNoticeEvent:群成员增加事件
- GroupMessageEvent:群消息(通过该类的属性获取到 群QQ号)
- finish()函数:发送一条消息给当前交互用户并结束当前事件响应器
__init__.py 文件 在该文件中编写各类事件响应及处理逻辑
from nonebot import on_command, export
from nonebot.typing import T_State
from nonebot.adapters.cqhttp import Bot, Message, GroupMessageEvent, GroupDecreaseNoticeEvent, GroupIncreaseNoticeEvent
from nonebot import on_notice
export = export()
export.name = '进群欢迎'
export.usage = '欢迎新人'
welcom = on_notice()
@welcom.handle()
async def h_r(bot: Bot, event: GroupIncreaseNoticeEvent, state: T_State):
user = event.get_user_id()
at_ = "本群通过祈愿召唤了勇者大人:[CQ:at,qq={}]".format(user)
msg = at_ + '欢迎勇者大人:\n 您就是被命运召唤而来前来拯救我们的公会的勇者吗,快救救孩子们吧,希望勇者大人为我们而战!'
msg = Message(msg)
print(at_)
if event.group_id == QQ群号:
await welcom.finish(message=Message(f'{msg}'))
@welcom.handle()
async def h_r(bot: Bot, event: GroupDecreaseNoticeEvent, state: T_State):
user = event.get_user_id()
at_ = "[CQ:at,qq={}]".format(user)
msg = at_ + '勇士离开了本群,大家快出来送别它吧!'
msg = Message(msg)
print(at_)
if event.group_id == QQ群号:
await welcom.finish(message=Message(f'{msg}'))
存放在 plugins 目录下: 启动项目会自动加载 编写好的插件,插件目录一定要有 __init__.py 文件
|