三丰云搭建QQ-bot的服务器-代码实现(3)

网址:https://www.sanfengyun.com >> 三丰云免费云服务器

代码实现

书接上回装饰器,显而易见,只有装饰器还不完善,所以我们接着来补充代码

首先定义一个 MyClient 类

python 复制代码
class MyClient(botpy.Client):
    async def on_ready(self):
        _log.info(f"robot 「{self.robot.name}」 on_ready!")
# 加上这一条代码就能初步判断代码有没有成功跑起来了

接着补充测试代码

python 复制代码
judge_result = False
# 注册指令handler
handlers = [
    hello #可以继续补充
]
for handler in handlers:
if await handler(api=self.api, message=message):
    judge_result = True
    return  judge_result
if judge_result==False:
    messageResult = await message._api.post_group_message(
        group_openid=message.group_openid,
          msg_type=0, 
          msg_id=message.id,
          content=f"{bot_functions.repeater(message.content)}")
        _log.info(messageResult)

有了这段代码,里能够正常跑起来就不远了

相关推荐
技术不支持6 小时前
Qt Creator 11.0.3 语法高亮bug问题
java·服务器·数据库·qt·bug
易ლ拉罐7 小时前
【计算机网络】Socket网络编程
服务器·网络·计算机网络
大大大大肉包7 小时前
linux中挂载磁盘和卸载
linux·运维·服务器
new对象吗什么类型都有8 小时前
服务器中切换盘的操作指南
运维·服务器
jxy pro max8 小时前
Corrosion2靶机练习笔记
服务器·网络·笔记
CODE_RabbitV12 小时前
Linux 文件与目录操作命令宝典
linux·运维·服务器
caz2812 小时前
麒麟服务器版操作系统添加VNC
linux·服务器·centos·vnc
Doris_LMS13 小时前
rsync远程同步工具使用(保姆级别)
linux·服务器
海域云SeaArea_14 小时前
Rustdesk中继服务器搭建(windows 服务器)
运维·服务器·windows
云动雨颤15 小时前
WordPress安全加速:Cloudflare + Nginx缓存优化方案
服务器·wordpress