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

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

相关推荐
Bug退散师42 分钟前
多路IO复用[select版TCP服务器与poll版TCP服务器]与常用网络编程函数详解
linux·服务器·c语言·网络·驱动开发·tcp/ip
国服第二切图仔1 小时前
05-构建与特性开关
linux·服务器·ubuntu
风曦Kisaki2 小时前
# Linux 系统资源查看命令总结(附命令快查表)
linux·运维·服务器
蝶恋舞者3 小时前
DNS 服务器(后续持续更新)
运维·服务器
Mortalbreeze3 小时前
深入理解 Linux 线程机制(四):线程同步——条件变量与信号量
linux·运维·服务器·开发语言·c++
Huangjin007_4 小时前
【Linux 系统篇(一)】入门基础指令详解(一)
linux·服务器
会飞的小新4 小时前
《深入理解 DDR Memory Margin》系列之第一章:从 DDR 到 Memory Margin——为什么服务器需要进行内存裕量测试?
linux·服务器
汤愈韬4 小时前
KYCA运维认证
运维·服务器·网络
晚风吹长发4 小时前
探索软件测试——用例篇
大数据·linux·服务器·压力测试·测试·测试方法
ZENERGY-众壹4 小时前
50MW分布式VPP接入实战:调度中心要求的1分钟频率如何不卡死API
运维·服务器·分布式·光伏运维