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

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

相关推荐
weixin_5206498741 分钟前
Modbus RTU
linux·运维·服务器
zhangfeng113343 分钟前
超算中心 高性能计算 slurm的linux版本 centos7,如何安装docker,如何安装torch2.4
linux·运维·服务器·开发语言·人工智能·机器学习·docker
青皮桔1 小时前
Prometheus + Grafana实现服务器监控
服务器·grafana·prometheus
weixin_604236671 小时前
华为三层交换机 极简完整版配置
运维·服务器·华为·华为交换机·华为交换机命令
Configure-Handler1 小时前
linux-kernel-fault-codes
linux·运维·服务器
运维行者_1 小时前
通过Applications Manager的TCP监控确保无缝网络连接
运维·服务器·网络·数据库·人工智能
路人蛃1 小时前
【深入理解计算机系统】第二章第一节(信息存储)笔记
服务器·网络·笔记·计算机网络·系统架构
一勺菠萝丶1 小时前
Linux 服务器临时用户创建与删除教程
linux·运维·服务器
lunzi_08261 小时前
《图解HTTP》--第5章-与HTTP协作的Web服务器
服务器·前端·http
2401_868534782 小时前
防火墙的具体概念
服务器·网络·php