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

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

相关推荐
国服第二切图仔1 小时前
Rust开发之使用anyhow与thiserror简化错误处理
服务器·数据库·rust
笨蛋少年派1 小时前
*清理磁盘空间
linux·运维·服务器
慕木沐2 小时前
【搭建个人网站】借助内网穿透+云服务器中转
运维·服务器
染指秃头3 小时前
VM虚拟机共享宿主机代理(Ubuntu24.04)
linux·运维·服务器
Wang's Blog3 小时前
Linux小课堂: Squid代理缓存服务器部署与访问控制实战指南
linux·服务器·缓存
priority_key4 小时前
TCP 如何保证传输的可靠性?
服务器·网络·后端·网络协议·tcp/ip
深鱼~4 小时前
从本地存储到全球访问:1Panel的家庭服务器革命
大数据·运维·服务器
栀椩4 小时前
frp+公网服务器实现内网穿透方案
运维·服务器
2501_938791224 小时前
VsCode 远程模式 + 服务器:Github Copilot 安装后无法触发?原因解析
服务器·vscode·github
爬台阶的蚂蚁4 小时前
内网麒麟系统安装 uv 的完整步骤
运维·服务器·uv