三丰云搭建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)

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

相关推荐
wadesir35 分钟前
简易制作LinuxShell完全指南(深入解析原理、设计与实践步骤)
linux·运维·服务器
杰克崔2 小时前
glibc社区提问
linux·运维·服务器·车载系统
wqdian_com2 小时前
中文域名的准确展示能否堵住网络钓鱼攻击“后门”?
服务器·安全·php
代码游侠2 小时前
应用——Web服务器项目代码解析
运维·服务器·开发语言·前端·笔记·html
yueguangni3 小时前
centos7虚拟机nat模式连接不上xshell方法分享
linux·运维·服务器
阿巴~阿巴~3 小时前
TCP性能优化秘籍:延迟应答、捎带确认与粘包破解之道
运维·服务器·网络·网络协议·udp·tcp
HuaYi_Sir3 小时前
i.MX6ULL移植uboot Linux buildroot(二)
linux·运维·服务器
java_logo4 小时前
Docker 部署银河麒麟高级服务器操作系统(Kylin Linux)生产级全流程
服务器·docker·kylin·银河麒麟部署·银河麒麟部署文档·银河麒麟linux·银河麒麟linux部署教程
航Hang*4 小时前
第五章:网络系统建设与运维(高级)—— VLAN高级特性
运维·服务器·网络·笔记·计算机网络·华为·ensp
小鹏linux4 小时前
【像素贪吃蛇小游戏】部署文档-linux篇
linux·运维·服务器