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

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

相关推荐
源远流长jerry9 小时前
Linux 网络发送机制深度解析:从应用到网线
linux·服务器·网络·网络协议·tcp/ip
goyeer10 小时前
【ITIL4】32服务实践 - 问题管理(Problem Management)
linux·运维·服务器·企业数字化·it管理·itil·it治理
cen__y11 小时前
Linux11(网络编程)
linux·运维·服务器·c语言·网络·网络协议·tcp/ip
CableTech_SQH11 小时前
商业地产和高端酒店该怎么选综合布线解决方案?
运维·服务器·网络
Y\11 小时前
VMware虚拟机已断开连接解决方法(二)
服务器
isyangli_blog12 小时前
vmware 安装 Windows Server 2012
服务器
怀旧,12 小时前
【Linux网络编程】9. 数据链路层
linux·服务器·网络
QotomPC12 小时前
Qotom Q30900GP多网口Mini PC:16网口设计在pfSense与工业网络中的应用
服务器·网络·边缘计算
Liangwei Lin13 小时前
LeetCode 22. 括号生成
linux·运维·服务器
( •̀∀•́ )92013 小时前
Linux 下部署 `social-auto-upload` 遇到的问题及完整解决方案
linux·运维·服务器