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

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

相关推荐
Xの哲學1 小时前
Linux SLUB 内存分配器深度剖析: 从设计哲学到实战调试
linux·服务器·网络·算法·边缘计算
何中应1 小时前
linux使用root账户操作提示没有权限
linux·运维·服务器
天上飞的粉红小猪1 小时前
网络基础概念
linux·服务器·网络·c++
KingRumn2 小时前
DBUS源码剖析之DBusMessage消息头
linux·服务器·算法
qq_5470261792 小时前
Linux 压缩与解压缩
linux·运维·服务器
QT 小鲜肉2 小时前
【Linux命令大全】003.文档编辑之csplit命令(实操篇)
linux·运维·服务器·chrome·mysql
itas1092 小时前
Linux交叉编译工具链
linux·运维·服务器·交叉编译·cross-compile
QT 小鲜肉3 小时前
【Linux命令大全】002.文件传输之lpr命令(实操篇)
linux·运维·服务器·网络·chrome·笔记
最后一个bug3 小时前
为什么linux内存要分DMA区域,常规区域和高端内存区域?
linux·服务器·开发语言·系统架构·计算机外设
qq_447429413 小时前
Qwen Code CanUseTool 实现分析
linux·运维·服务器