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

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

相关推荐
佑白雪乐14 分钟前
<Linux基础第10集>复习前面内容
linux·运维·服务器
春日见17 分钟前
自动驾驶规划控制决策知识点扫盲
linux·运维·服务器·人工智能·机器学习·自动驾驶
landonVM2 小时前
Linux 上搭建 Web 服务器
linux·服务器·前端
云游云记2 小时前
nesbot/carbon 常用功能总结
linux·运维·服务器
landonVM2 小时前
Linux 下的高效压缩工具 Zstandard
linux·运维·服务器
遇见火星2 小时前
服务器运维操作命令速查手册
运维·服务器
EmbedLinX3 小时前
Linux之内存管理
linux·服务器·c语言·c++
2301_792580003 小时前
xuepso
java·服务器·前端
Nightwish53 小时前
Linux随记(二十八)
linux·运维·服务器
Zach_yuan3 小时前
Socket 编程基础
linux·服务器