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

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

相关推荐
L Jiawen1 小时前
【Golang基础】基础知识(下)
服务器·开发语言·golang
haimin03713 小时前
linux设置CPU固定频率
linux·运维·服务器
一条咸鱼¥¥¥3 小时前
【运维经验】服务器磁盘做镜像的方法
运维·服务器·windows·经验分享
渣渣盟3 小时前
NFS服务器配置全攻略:从入门到精通
linux·运维·服务器
一只旭宝3 小时前
Linux专题九:I/O复用(水平以及边缘触发放到libevent库那一专题细讲)
linux·运维·服务器
缘如风4 小时前
Linux上sunrpc 111端口关闭
linux·服务器
I · T · LUCKYBOOM4 小时前
iptables防火墙
linux·运维·服务器·网络·安全
鸠摩智首席音效师5 小时前
如何在 Linux 中使用 uptime 命令 ?
linux·运维·服务器
HalvmånEver5 小时前
Linux:匿名管道(进程间通信二)
linux·运维·服务器
lengjingzju5 小时前
一网打尽Linux IPC(一):进程间通信完全指南——总体介绍
linux·服务器·c语言