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

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

相关推荐
7***n7518 分钟前
API网关设计模式
linux·服务器·设计模式
zzzsde2 小时前
【Linux】基础开发工具(1):软件包管理器&&vim编辑器
linux·运维·服务器
橘子真甜~2 小时前
C/C++ Linux网络编程6 - poll解决客户端并发连接问题
服务器·c语言·开发语言·网络·c++·poll
zwm_yy3 小时前
服务器检查内存爆满
运维·服务器
摩尔元数3 小时前
2025,服务器通信MES厂商谁主沉浮?
运维·服务器
last demo3 小时前
nfs服务器
linux·运维·服务器·php
翼龙云_cloud3 小时前
阿里云渠道商:自建或RDS怎么迁移到阿里云PolarDB?
运维·服务器·阿里云·云计算
q***76664 小时前
RustDesk搭建公网中继服务器远控内网机器(完整版)
运维·服务器
淼_@淼5 小时前
pytest简介
运维·服务器·pytest
濊繵5 小时前
Linux网络--应用层自定义协议与序列化
linux·服务器·网络