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

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

相关推荐
hhzz13 小时前
云服务器ECS的高可用部署方案----弹性公网IP和负载均衡的操作
服务器·tcp/ip·负载均衡·ecs·云服务器
吕司14 小时前
Linux——System V 共享内存
linux·运维·服务器
公子烨14 小时前
瞎玩openclaw
服务器
71ber14 小时前
RHCSE 实战笔记:Keepalived 企业级高可用集群深度解析
linux·服务器·keepalived
dong_beijing14 小时前
rtmp/flv直播源站搭建方法
服务器·centos·云计算
白太岁14 小时前
Muduo:(5) 主 Reactor 之 Acceptor 与 SubReactor 的分发
服务器·网络·c++·网络协议·tcp/ip
天上飞的粉红小猪14 小时前
数据链路层
linux·服务器·网络
开发者导航15 小时前
精选高质量网址资源的高效聚合综合性的网址导航:跳跳兔导航网
服务器·人工智能·程序人生·搜索引擎·开源软件
funnycoffee1231 天前
linux系统DNS修改命令
linux·运维·服务器·linux dns
清漠2331 天前
win11“网络和Internet“中无“以太网“这个选项解决记录
服务器·网络·数据库