Code Monkey home page Code Monkey logo

adapter-qq's Introduction

NoneBot

License PyPI Python Version OneBot Version QQ 群 Telegram 频道 Discord Server

简介

NoneBot 是一个基于 OneBot 标准(原 CQHTTP) 的 Python 异步 QQ 机器人框架,它会对 QQ 机器人收到的消息进行解析和处理,并以插件化的形式,分发给消息所对应的命令处理器和自然语言处理器,来完成具体的功能。

除了起到解析消息的作用,NoneBot 还为插件提供了大量实用的预设操作和权限控制机制,尤其对于命令处理器,它更是提供了完善且易用的会话机制和内部调用机制,以分别适应命令的连续交互和插件内部功能复用等需求。

NoneBot 在其底层与 OneBot 实现交互的部分使用 aiocqhttp 库,后者在 Quart 的基础上封装了与 OneBot 实现的网络交互。

得益于 Python 的 asyncio 机制,NoneBot 处理消息的吞吐量有了很大的保障,再配合 OneBot 标准的 WebSocket 通信方式(也是最建议的通信方式),NoneBot 的性能可以达到 HTTP 通信方式的两倍以上,相较于传统同步 I/O 的 HTTP 通信,更是有质的飞跃。

需要注意的是,NoneBot 仅支持 Python 3.7+。

文档

文档目前「指南」和「API」部分已经完成,「进阶」部分尚未完成,你可以在 这里 查看。

贡献

如果你在使用过程中发现任何问题,可以 提交 issue 或自行 fork 修改后提交 pull request。

如果你要提交 pull request,请确保你的代码风格和项目已有的代码保持一致,遵循 PEP 8,变量命名清晰,有适当的注释。

NoneBot

Description

NoneBot is an asynchronous and OneBot-compliant QQ robot framework written in Python. When NoneBot receives new messages, it parses the messages then pass them to user-defined command handlers or natural language processors accordingly using a plugin system to accomplish various tasks.

Beside message processing, NoneBot presents an amount of useful built-in actions and permission handling features. The command processors provide simple but comprehensive session-ing and calling mechanisms to handle continuous interactions and the reusing of functionalities inside plugins, respectively.

NoneBot communicates with OneBot implementations using aiocqhttp, a wrapper based on Quart for lower-level protocol work.

Thanks to asyncio and WebSocket messaging method (which is recommended), NoneBot ensures maximum possible message throughput to be twice as fast as HTTP messaging, and have great performance leap compared to traditional synchronous IO.

NoneBot only supports Python 3.7+.

Documentation

For Guide and API manuals, check out this page.

Contributing

If you encounter any problems in using the project, you can submit an issue or fork this project to submit an pull request.

For pull requests, please be sure to have consistent style to existing modules, follow PEP 8, have clear identifier naming, and have proper comments.

adapter-qq's People

Contributors

17theword avatar ailitonia avatar cmhopesunshine avatar dependabot[bot] avatar dreamail avatar felinae98 avatar he0119 avatar iris7656 avatar kimigaiiwuyi avatar mingxuangame avatar mobyw avatar pre-commit-ci[bot] avatar rf-tar-railt avatar ssttkkl avatar starhearthunt avatar xapenny avatar yanyongyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

adapter-qq's Issues

无法启动

'''

Attempting uninstall: nonebot2
Found existing installation: nonebot2 2.0.0
Uninstalling nonebot2-2.0.0:
Successfully uninstalled nonebot2-2.0.0
Successfully installed nonebot-adapter-qq-1.0.0 nonebot2-2.1.1 typing-extensions-4.8.0
WARNING: You are using pip version 20.2.3; however, version 23.2.1 is available.
You should consider upgrading via the '/usr/local/py/bin/python3.8 -m pip install --upgrade pip' command.
[root@RainYun-H6oVCZwf Chiyuki-Bot]# py bot.py
10-03 18:20:19 [SUCCESS] nonebot | NoneBot is initializing...
10-03 18:20:19 [INFO] nonebot | Current Env: prod
Traceback (most recent call last):
File "bot.py", line 21, in
app = nonebot.get_asgi()
File "/usr/local/py/lib/python3.8/site-packages/nonebot/init.py", line 190, in get_asgi
assert isinstance(
AssertionError: asgi object is only available for asgi driver
'''

无法登录到群Bot

安装adapter-qq后运行nb run显示如下内容:
11-10 05:18:32 [DEBUG] nonebot | Succeeded to load adapter "QQ"
11-10 05:18:32 [DEBUG] nonebot | Succeeded to load adapter "Minecraft"
11-10 05:18:32 [SUCCESS] nonebot | Succeeded to load plugin "uniseg" from "nonebot_plugin_alconna.uniseg"
11-10 05:18:32 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_alconna"
11-10 05:18:33 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_status"
11-10 05:18:33 [SUCCESS] nonebot | Running NoneBot...
11-10 05:18:33 [DEBUG] nonebot | Loaded adapters: QQ, Minecraft
11-10 05:18:34 [INFO] uvicorn | Started server process [837869]
11-10 05:18:34 [INFO] uvicorn | Waiting for application startup.
11-10 05:18:34 [DEBUG] nonebot | QQ Guild | QQ run in sandbox mode: True
11-10 05:18:34 [DEBUG] nonebot | QQ Guild | QQ api base url: https://sandbox.api.sgroup.qq.com
11-10 05:18:34 [DEBUG] nonebot | QQ Guild | Bot 3889000112 calling API shard_url_get
11-10 05:18:34 [INFO] uvicorn | Application startup complete.
11-10 05:18:34 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
11-10 05:18:34 [ERROR] nonebot | QQ Guild | Failed to get gateway info.
Traceback (most recent call last):
File "", line 19, in
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/init.py", line 331, in run
get_driver().run(*args, **kwargs)
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/drivers/fastapi.py", line 201, in run
uvicorn.run(
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/uvicorn/main.py", line 587, in run
server.run()
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/uvicorn/server.py", line 61, in run
return asyncio.run(self.serve(sockets=sockets))
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)

File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/adapter.py", line 105, in run_bot
gateway_info = await bot.shard_url_get()
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
raise exception
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
result = await self.adapter._call_api(self, api, **data)
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/adapter.py", line 415, in _call_api
return await api_handler(bot, **data)
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/utils.py", line 64, in call
return await self.func(inst, *args, **kwds)
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/bot.py", line 1508, in shard_url_get
return parse_obj_as(ShardUrlGetReturn, await self._request(request))
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/bot.py", line 459, in _request
request.headers.update(await self.get_authorization_header())
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/bot.py", line 266, in get_authorization_header
headers = {"Authorization": await self._get_authorization_header()}
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/bot.py", line 261, in _get_authorization_header
return f"QQBot {await self.get_access_token()}"
File "/home/bot/xt/rootfs/home/NightWind-qq/.venv/lib/python3.8/site-packages/nonebot/adapters/qq/bot.py", line 252, in get_access_token
self._access_token = cast(str, data["access_token"])
KeyError: 'access_token'

.env文件如下:

NVIRONMENT=dev
DRIVER=~fastapi+~httpx+~websockets+~aiohttp

QQ_BOTS='
[
{
"id": "3xxxxxxxx2",
"token": "mxxxxxxxxxxxxxxxxxxxDu",
"secret": "zxxxxxxxxxxxxxx8J",
"intent": {
"c2c_group_at_messages": true
}
}
]
'

Bot无法启动

在最下面加载消息之后不再加载消息,导致无法启动

Microsoft Windows [版本 10.0.20348.1366]
(c) Microsoft Corporation。保留所有权利。

C:\Users\Lsrl>cd nb

C:\Users\Lsrl\nb>nb run
使用 Python: C:\Users\Lsrl\nb\.venv\Scripts\python.exe
10-08 21:25:36 [SUCCESS] nonebot | NoneBot is initializing...
10-08 21:25:36 [INFO] nonebot | Current Env: prod
10-08 21:25:36 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
10-08 21:25:37 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_picmcstat"
10-08 21:25:37 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
10-08 21:25:37 [INFO] nonebot_plugin_admin | 已检测到软依赖nonebot_plugin_apscheduler, 开启定时任务功能
10-08 21:25:38 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_admin"
10-08 21:25:38 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_alias"
10-08 21:25:38 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_crazy_thursday"
C:\Users\Lsrl\nb\.venv\lib\site-packages\fuzzywuzzy\fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
  warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')
10-08 21:25:38 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_PicMenu"
10-08 21:25:38 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_russian"
10-08 21:25:39 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
10-08 21:25:41 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_memes"
10-08 21:25:41 [INFO] nonebot_plugin_steam_game_status | steam_web_key 读取成功
10-08 21:25:41 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_steam_game_status"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_chatrecorder"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_wordcloud"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_who_at_me"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_follow_withdraw"
10-08 21:25:42 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_picstatus"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_htmlrender"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_bawiki"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_guild_patch"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_dialectlist"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_apscheduler"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_saa"
10-08 21:25:43 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_capoo"
10-08 21:25:43 [SUCCESS] nonebot | Running NoneBot...
10-08 21:25:43 [INFO] nonebot_plugin_apscheduler | Scheduler Started
10-08 21:25:47 [WARNING] nonebot_plugin_crazy_thursday | Abort downloading
10-08 21:25:47 [INFO] nonebot_plugin_memes | 正在检查资源文件...
10-08 21:25:47 [INFO] nonebot_plugin_datastore | 数据库初始化完成
10-08 21:25:48 [INFO] nonebot_plugin_htmlrender | 使用 chromium 启动
10-08 21:25:48 [INFO] nonebot_plugin_htmlrender | Browser Started.
10-08 21:25:48 [INFO] nonebot_plugin_capoo | 配置项未选择本地存储图片,将通过url发送图片
10-08 21:25:48 [INFO] nonebot | Application startup completed.

群消息不需要转义 <>

别的没测,直接把

return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
给替换成原封不动返回了。

修改之前:
<> 被转义为 &lt; &gt;,群没转义回来,频道正常

修改之后:
没转义,群正常,频道正常,但是我加的额外 logger 炸了(因为把 <> 以为是颜色符号

image

Feature: 转换QQ频道消息

由于频道的消息序列化存在N多的问题,暂时无法将频道消息转换为nb内部消息来进行command匹配等操作

等待官方重新设计内嵌格式或者其他解决方案(2021年12月提出的问题至今未给出)

# Bug(?)

在频道中发消息,机器人接收到消息后对频道好友广播了一遍,号秒封
2c707502bf28772f

无法转换频道私聊信息为一个Event

10-21 18:02:08 [WARNING] nonebot | QQ Guild | Failed to parse event Dispatch(opcode=<Opcode.DISPATCH: 0>, data={'author': {'avatar': 'https://qqchannel-profile-1251316161.file.myqcloud.com/16533256150e7147ab420eceb66?t=1653325650', 'id': '16362846582326858170', 'username': 'kkkkkk'}, 'channel_id': '210451697880338', 'content': 'q', 'direct_message': True, 'guild_id': '13595572922435876753', 'id': '0891efd6fda5b1cbd6bc0110929ac7d5f9ec2f3804489fc3cea906', 'member': {'joined_at': '2023-10-21T17:25:38+08:00'}, 'seq': 4, 'seq_in_channel': '4', 'src_guild_id': '7088881514225344423', 'timestamp': '2023-10-21T18:02:07+08:00'}, sequence=5, type='DIRECT_MESSAGE_CREATE', id='DIRECT_MESSAGE_CREATE:0891efd6fda5b1cbd6bc0110929ac7d5f9ec2f3804489fc3cea906')
Traceback (most recent call last):
  File "D:\code\py\bot\bot.py", line 18, in <module>
    nonebot.run()
  File "C:\Users\A\.conda\envs\botenv\lib\site-packages\nonebot\__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "C:\Users\A\.conda\envs\botenv\lib\site-packages\nonebot\drivers\none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "C:\Users\A\.conda\envs\botenv\lib\asyncio\base_events.py", line 636, in run_until_complete
    self.run_forever()
  File "C:\Users\A\.conda\envs\botenv\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\A\.conda\envs\botenv\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "C:\Users\A\.conda\envs\botenv\lib\asyncio\base_events.py", line 1909, in _run_once
    handle._run()
  File "C:\Users\A\.conda\envs\botenv\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\A\.conda\envs\botenv\lib\site-packages\nonebot\adapters\qq\adapter.py", line 180, in _forward_ws
    await self._loop(bot, ws)
> File "C:\Users\A\.conda\envs\botenv\lib\site-packages\nonebot\adapters\qq\adapter.py", line 344, in _loop
    event = self.payload_to_event(payload)
  File "C:\Users\A\.conda\envs\botenv\lib\site-packages\nonebot\adapters\qq\adapter.py", line 407, in payload_to_event
    return EventClass.parse_obj(payload.data)
  File "pydantic\main.py", line 526, in pydantic.main.BaseModel.parse_obj
    return cls(**obj)
  File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for DirectMessageCreateEvent
member -> roles
  field required (type=value_error.missing)

配置如下:
DRIVER=~fastapi+~websockets+~httpx
DRIVER=~aiohttp
QQ_IS_SANDBOX=false
QQ_BOTS='
[
{
"id": "?",
"token": "?",
"secret": "?",
"intent": {
"guild_messages": true,
"at_messages": false,
"direct_message": true
}
}
]
'

启动后没有登录到QQ频道Bot

在根据文档填写.env后,启动Bot没有显示登录信息,显示如下:

10-09 13:35:44 [DEBUG] nonebot | Succeeded to load adapter "QQ Guild"
10-09 13:35:44 [SUCCESS] nonebot | Succeeded to load plugin "echo" from "nonebot.plugins.echo"
10-09 13:35:44 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_jrrp2" from "src.plugins.nonebot_plugin_jrrp2"
10-09 13:35:44 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_localstore"
10-09 13:35:46 [DEBUG] nonebot_plugin_datastore | 创建数据库文件夹: /root/.local/share/nonebot2
10-09 13:35:46 [DEBUG] nonebot_plugin_datastore | 数据库连接地址: sqlite+aiosqlite:////root/.local/share/nonebot2/data.db
10-09 13:35:46 [DEBUG] nonebot_plugin_datastore | 数据库引擎参数: {'echo': False, 'echo_pool': False}
10-09 13:35:46 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_datastore"
10-09 13:35:47 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_saa"
10-09 13:35:47 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_emojimix"
10-09 13:35:47 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_session"
10-09 13:35:49 [SUCCESS] nonebot | Succeeded to load plugin "nonebot_plugin_minesweeper"
10-09 13:35:49 [SUCCESS] nonebot | Running NoneBot...
10-09 13:35:49 [DEBUG] nonebot | Loaded adapters: OneBot V11, QQ Guild
10-09 13:35:49 [INFO] uvicorn | Started server process [1603389]
10-09 13:35:49 [INFO] uvicorn | Waiting for application startup.
10-09 13:35:49 [DEBUG] nonebot | QQ Guild | QQ Guild run in sandbox mode: False
10-09 13:35:49 [DEBUG] nonebot | QQ Guild | QQ Guild api base url: https://api.sgroup.qq.com/
10-09 13:35:50 [DEBUG] nonebot_plugin_datastore | 初始化插件 nonebot_plugin_session 的数据库
10-09 13:35:50 [INFO] nonebot_plugin_datastore | 数据库初始化完成
10-09 13:35:50 [INFO] uvicorn | Application startup complete.
10-09 13:35:50 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:8082 (Press CTRL+C to quit)``


.env中的内容:

ENVIRONMENT=dev
DRIVER=~fastapi+~httpx+~websockets+~aiohttp
QQ_BOTS='
[
  {
    "id": "隐藏",
    "token": "隐藏",
    "secret": "隐藏",
    "intent": {
      "guild_messages": true,
      "at_messages": false
    }
  }
]
'

Bug: 群机器人无法正常发送语音

发送使用MessageSegment.audio(audio_url)发送silk格式语音失败并报错
<ActionFailed: 500, code=850019, message=不支持的文件格式, trace_id=xxx>

Bug: 群机器人无法使用沙箱频道

当在.env文件中将 c2c_group_at_messages 设置为true后,在沙箱频道触发指令会有以下报错

File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot_plugin_handle/__init__.py", line 207, in handle_handle
    await send(f"你有{game.times}次机会猜一个四字成语,请发送成语", game.draw())
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot_plugin_handle/__init__.py", line 190, in send
    await bot.send(event,msg)
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 415, in send
    return await self.send_to_channel(
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 326, in send_to_channel
    return await self.post_messages(
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 123, in call_api
    raise exception
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/internal/adapter/bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/adapter.py", line 415, in _call_api
    return await api_handler(bot, **data)
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/utils.py", line 64, in __call__
    return await self.func(inst, *args, **kwds)
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 918, in post_messages
    return parse_obj_as(GuildMessage, await self._request(request))
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 488, in _request
    raise ex from None
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 486, in _request
    return self._handle_response(response)
  File "/home/dmc/.envs/guild/lib/python3.11/site-packages/nonebot/adapters/qq/bot.py", line 450, in _handle_response
    raise UnauthorizedException(response)
nonebot.adapters.qq.exception.UnauthorizedException: <ActionFailed: 401, code=11200, message=parse appid err, data=None>

只有设置"public_guild_messages":true ,删除c2c_group_at_messages配置,才能正常向频道内发送消息

请求适配消息撤回事件

这个事件本身对我没什么用处, 但是无法解析这个事件导致经常报错.
( 或者有什么办法让它忽略这个事件吗

03-15 12:15:09 [WARNING] nonebot | QQ Guild | Failed to parse event Dispatch(opcode=<Opcode.DISPATCH: 0>, data={'message': {'author': {'bot': False, 'id': '537106425******', 'username': '白昼梦游指北'}, 'channel_id': '246******', 'guild_id': '74010238******', 'id': '089890b6fbf3fdedda6610b887db75385b4******'}, 'op_user': {'id': '5371064253******'}}, sequence=2, type='MESSAGE_DELETE', id='MESSAGE_DELETE:9ef1e775-de71-4cc2-8e48-ddf366adb680')
Traceback (most recent call last):
  File "/home/Nonebot/bot.py", line 29, in <module>
    nonebot.run(app="__mp_main__:app")
  File "/usr/local/lib/python3.10/dist-packages/nonebot/__init__.py", line 273, in run
    get_driver().run(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/nonebot/drivers/fastapi.py", line 187, in run
    uvicorn.run(
  File "/usr/local/lib/python3.10/dist-packages/uvicorn/main.py", line 569, in run
    server.run()
  File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
> File "/usr/local/lib/python3.10/dist-packages/nonebot/adapters/qqguild/adapter.py", line 216, in _forward_ws
    event = self.payload_to_event(payload)
  File "/usr/local/lib/python3.10/dist-packages/nonebot/adapters/qqguild/adapter.py", line 303, in payload_to_event
    event = Event.parse_obj(payload.data)
  File "/usr/local/lib/python3.10/dist-packages/pydantic/main.py", line 526, in parse_obj
    return cls(**obj)
TypeError: Can't instantiate abstract class Event with abstract method get_type
03-15 12:15:09 [WARNING] nonebot | QQ Guild | Unknown payload type: PUBLIC_MESSAGE_DELETE
03-15 12:15:09 [WARNING] nonebot | QQ Guild | Failed to parse event Dispatch(opcode=<Opcode.DISPATCH: 0>, data={'message': {'author': {'bot': False, 'id': '5371064253740******', 'username': '白昼梦游指北'}, 'channel_id': '2468******', 'guild_id': '74010238******', 'id': '089890b6fbf3fdedda6610b887db75385b488******'}, 'op_user': {'id': '5371064253******'}}, sequence=3, type='PUBLIC_MESSAGE_DELETE', id='PUBLIC_MESSAGE_DELETE:e92b1aef-995a-472a-9a0c-f83b446b2720')
Traceback (most recent call last):
  File "/home/Nonebot/bot.py", line 29, in <module>
    nonebot.run(app="__mp_main__:app")
  File "/usr/local/lib/python3.10/dist-packages/nonebot/__init__.py", line 273, in run
    get_driver().run(*args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/nonebot/drivers/fastapi.py", line 187, in run
    uvicorn.run(
  File "/usr/local/lib/python3.10/dist-packages/uvicorn/main.py", line 569, in run
    server.run()
  File "/usr/local/lib/python3.10/dist-packages/uvicorn/server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
> File "/usr/local/lib/python3.10/dist-packages/nonebot/adapters/qqguild/adapter.py", line 216, in _forward_ws
    event = self.payload_to_event(payload)
  File "/usr/local/lib/python3.10/dist-packages/nonebot/adapters/qqguild/adapter.py", line 303, in payload_to_event
    event = Event.parse_obj(payload.data)
  File "/usr/local/lib/python3.10/dist-packages/pydantic/main.py", line 526, in parse_obj
    return cls(**obj)
TypeError: Can't instantiate abstract class Event with abstract method get_type

日志中中的ID被我去掉了

谢谢!

无法连接至QQ - SSL证书验证失效

我尝试在Python 3.11.6运行NoneBot Adapter QQ,但是框架报错“SSL证书验证失败”(GPT分析)
框架版本:nb-cli 1.2.6
操作系统已关闭防火墙并开放所有出入站规则
错误如下:

11-17 20:46:37 [ERROR] nonebot | QQ | Failed to get gateway info.
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 980, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1112, in create_connection
transport, protocol = await self._create_connection_transport(
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1145, in _create_connection_transport
await waiter
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\sslproto.py", line 575, in _on_handshake_complete
raise handshake_exc
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\sslproto.py", line 557, in _do_handshake
self._sslobj.do_handshake()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\ssl.py", line 979, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\bot.py", line 461, in _request
response = await self.adapter.request(request)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\internal\adapter\adapter.py", line 90, in request
return await self.driver.request(setup)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\drivers\aiohttp.py", line 73, in request
async with session.request(
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\client.py", line 1167, in aenter
self._resp = await self._coro
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\client.py", line 562, in _request
conn = await self._connector.connect(
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 540, in connect
proto = await self._create_connection(req, traces, timeout)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 901, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 1209, in _create_direct_connection
raise last_exc
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 1178, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\aiohttp\connector.py", line 982, in _wrap_create_connection
raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host api.sgroup.qq.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)')]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "", line 15, in
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot_init_.py", line 331, in run
get_driver().run(*args, **kwargs)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\drivers\none.py", line 70, in run
loop.run_until_complete(self._serve())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
self.run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
super().run_forever()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
self._run_once()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1922, in _run_once
handle._run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
》 File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\adapter.py", line 105, in run_bot
gateway_info = await bot.shard_url_get()
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api
raise exception
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
result = await self.adapter._call_api(self, api, **data)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\adapter.py", line 416, in _call_api
return await api_handler(bot, **data)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\utils.py", line 64, in call
return await self.func(inst, *args, **kwds)
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\bot.py", line 1507, in shard_url_get
return parse_obj_as(ShardUrlGetReturn, await self._request(request))
File "C:\Users\Administrator\Desktop\SPS_Bot.venv\Lib\site-packages\nonebot\adapters\qq\bot.py", line 463, in _request
raise NetworkError("API request failed") from e
nonebot.adapters.qq.exception.NetworkError:

GPT输出
此为GPT输出的结果,而我在另一台电脑上能正常使用
另一台电脑的框架版本:nb-cli 1.2.5
是否是nb-cli的版本问题导致QQ适配器不兼容?

补充一下:我尝试检查SSL库,发现两主机的库均为2023.07.22(即最新版)
正在尝试指定nb.exe的出入站规则...

qq频道适配器安装失败

nb adapter install nonebot-adapter-qqguild

好像是并未发布这个包,我在商店看见的 https://v2.nonebot.dev/store

$ nb adapter install nonebot-adapter-qqguild

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
ERROR: Could not find a version that satisfies the requirement nonebot-adapter-qqguild (from versions: none)
ERROR: No matching distribution found for nonebot-adapter-qqguild

Bug:echo插件无作用

消息内容如下:
image

有确定收到ws消息:(pc上有\xa0,手机为空格)
image

from nonebot.rule import to_me
from nonebot.adapters import Message
from nonebot.params import CommandArg
from nonebot.plugin import on_command

echo = on_command("echo",to_me())


@echo.handle()
async def echo_escape(message: Message = CommandArg()):
    await echo.send(message=message)

好像是 to_me() 的问题 不艾特就可以

机器人无法发送多张图片

测试代码:

image_count = wenxin_config.wenxin_image_count # 图片数量
        msg = Message(f'文心原创绘画:主题为“{text}”的{style}') 
        for i in range(image_count): 
            msg += MessageSegment.image(images[i]['image'])
        await matcher.finish(msg)

效果:
在正常使用时(onebot11适配器)可以发送文字 + 多张图片,QQ频道适配器调用同样的代码只能发送出文字 + 第一张。

频道发送markdown消息报错

频道发送markdown消息时,会出现错误如下
nonebot.adapters.qq.exception.ActionFailed: <ActionFailed: 500, code=304041, message=reply messageg not allow markdown, trace_id=xxxxx>
频道应该发送md消息时不为reply

配置QQ 频道 协议时遇到如下错误

ERROR: Could not find a version that satisfies the requirement nonebot-adapter-qqguild (from versions: none)
ERROR: No matching distribution found for nonebot-adapter-qqguild

使用

nb adapter install nonebot-adapter-qqguild

也不行

下载图片出现问题

图片地址:https://wenxin.baidu.com/younger/file/ERNIE-ViLG/39d9837486e58bd78e74798e56017a535q

代码:

from nonebot import on_command
from nonebot.adapters.qqguild import MessageSegment

matcher = on_command("test")


@matcher.handle()
async def _():
    msg = MessageSegment.image("https://wenxin.baidu.com/younger/file/ERNIE-ViLG/39d9837486e58bd78e74798e56017a535q")
    await matcher.finish(msg)

报错:

08-26 19:01:43 [ERROR] nonebot | Running matcher <Matcher from drawer_bot.plugins.test, type=message, priority=1, temp=False> failed.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\tsing\miniconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "c:\users\tsing\miniconda3\lib\multiprocessing\spawn.py", line 129, in _main
    return self._bootstrap(parent_sentinel)
  File "c:\users\tsing\miniconda3\lib\multiprocessing\process.py", line 315, in _bootstrap
    self.run()
  File "c:\users\tsing\miniconda3\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\tsing\miniconda3\lib\site-packages\uvicorn\_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "c:\users\tsing\miniconda3\lib\site-packages\uvicorn\server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "c:\users\tsing\miniconda3\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "c:\users\tsing\miniconda3\lib\asyncio\base_events.py", line 634, in run_until_complete
    self.run_forever()
  File "c:\users\tsing\miniconda3\lib\asyncio\base_events.py", line 601, in run_forever
    self._run_once()
  File "c:\users\tsing\miniconda3\lib\asyncio\base_events.py", line 1905, in _run_once
    handle._run()
  File "c:\users\tsing\miniconda3\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\message.py", line 146, in _check_matcher
    await _run_matcher(Matcher, bot, event, state, stack, dependency_cache)
> File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\message.py", line 196, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\matcher.py", line 672, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\matcher.py", line 639, in simple_run
    await handler(
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\dependencies\__init__.py", line 92, in __call__
    return await self.call(**values)
  File "J:\myProject\机器人\nonebot2\drawer-bot\.\drawer_bot\plugins\test\__init__.py", line 10, in _
    await matcher.finish(msg)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\matcher.py", line 468, in finish
    await cls.send(message, **kwargs)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\matcher.py", line 453, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\adapters\qqguild\bot.py", line 144, in send
    return await self.post_messages(
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\adapter\bot.py", line 117, in call_api
    raise exception
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\internal\adapter\bot.py", line 94, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\adapters\qqguild\adapter.py", line 312, in _call_api
    return await api_handler(self, bot, **data)
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\adapters\qqguild\api\handle.py", line 275, in _post_messages
    return parse_obj_as(Message, await _request(adapter, bot, request))
  File "c:\users\tsing\miniconda3\lib\site-packages\nonebot\adapters\qqguild\api\request.py", line 34, in _request
    raise ActionFailed(data)
nonebot.adapters.qqguild.exception.ActionFailed: <ActionFailed: 500, code=40004, message=file not allow download, data=None>

无法连接

已确认appid token secret填写正确 尝试过重置token 仍无法正常链接
日志如下

03-14 12:52:37 [SUCCESS] nonebot | NoneBot is initializing...
03-14 12:52:37 [INFO] nonebot | Current Env: dev
03-14 12:52:37 [DEBUG] nonebot | Loaded Config: {'driver': '~fastapi+~websockets+~httpx', 'host': IPv4Address('127.0.0.1'), 'port': 9090, 'log_level': 'DEBUG', 'api_timeout': 30.0, 'superusers': set(), 'nickname': set(), 'command_start': {'/'}, 'command_sep': {'.'}, 'session_expire_timeout': datetime.timedelta(seconds=120), 'fastapi_reload': False, 'qqguild_bots': [{'id': '102****21', 'token': 'V7S******f7neEM', 'secret': 'bA******xxiJfr', 'intent': {'guild_messages': True, 'at_messages': False}}], 'environment': 'dev'}
03-14 12:52:38 [DEBUG] nonebot | Succeeded to load adapter "QQ Guild"
03-14 12:52:39 [SUCCESS] nonebot | Succeeded to import "echo"
03-14 12:52:39 [SUCCESS] nonebot | Running NoneBot...
03-14 12:52:39 [DEBUG] nonebot | Loaded adapters: QQ Guild
03-14 12:52:39 [INFO] uvicorn | Started server process [9408]
03-14 12:52:39 [INFO] uvicorn | Waiting for application startup.
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | QQ Guild run in sandbox mode: False
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | QQ Guild api base url: https://api.sgroup.qq.com/
03-14 12:52:39 [DEBUG] nonebot | QQ Guild | Calling API shard_url_get
03-14 12:52:39 [INFO] uvicorn | Application startup complete.
03-14 12:52:39 [INFO] uvicorn | Uvicorn running on http://127.0.0.1:9090 (Press CTRL+C to quit)
03-14 12:52:40 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:40 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:40 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:43 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:43 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:43 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:46 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
03-14 12:52:46 [INFO] nonebot | QQ Guild | Bot 102041021 connected
03-14 12:52:46 [ERROR] nonebot | QQ Guild | Received invalid session event from server. Try to reconnect...
03-14 12:52:47 [INFO] uvicorn | Shutting down
03-14 12:52:47 [INFO] uvicorn | Waiting for application shutdown.
03-14 12:52:47 [INFO] uvicorn | Application shutdown complete.
03-14 12:52:47 [INFO] uvicorn | Finished server process [9408]

Vscode 调试启动与 Windows终端启动问题

测试环境:Windows 11
Python版本:python 3.8 和 python 3.11

需要做插件测试如果用Vscode启动的话 pydantic 无法验证 qq_bots 这个值,如下图
{835D3C9A-D84D-4567-8674-852A8FEF0892}

但是用windows终端启动的话是一切正常的
{508420B5-AFF6-43b9-8BFE-3C449608E43A}

是否可以验证一下,虽然是个小问题

可以考虑暴露更多的Api

我在使用中发现,连post_message这样一个常用的Api也需要call_api才行

希望开发者可以暴露更多的常用Api给我们

(如果已经有了那当我没说)

Q:如何使用这个适配器

下面是启动报错

07-24 23:55:24 [ERROR] nonebot | QQ Guild | Error while process data from websocket wss://sandbox.api.sgroup.qq.com/websocket. Trying to reconnect...
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/__init__.py", line 333, in run
    get_driver().run(*args, **kwargs)
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/drivers/none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/adapters/qqguild/adapter.py", line 151, in _forward_ws
    result = await self._authenticate(bot, ws, shard)
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/adapters/qqguild/adapter.py", line 251, in _authenticate
    assert isinstance(
AssertionError: Received unexpected payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
07-24 23:55:24 [ERROR] nonebot | QQ Guild | Error while setup websocket to wss://sandbox.api.sgroup.qq.com/websocket. Trying to reconnect...
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/__init__.py", line 333, in run
    get_driver().run(*args, **kwargs)
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/drivers/none.py", line 70, in run
    loop.run_until_complete(self._serve())
  File "/usr/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/lib/python3.11/asyncio/base_events.py", line 1922, in _run_once
    handle._run()
  File "/usr/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/adapters/qqguild/adapter.py", line 180, in _forward_ws
    self.bot_disconnect(bot)
  File "/mnt/data/project/universal_bot/.venv/lib/python3.11/site-packages/nonebot/internal/adapter/adapter.py", line 70, in bot_disconnect
    raise RuntimeError(f"{bot} not found in adapter {self.get_name()}")
RuntimeError: Bot(type='QQ Guild', self_id=删除) not found in adapter QQ Guild
^C07-24 23:55:26 [INFO] nonebot | Shutting down
07-24 23:55:26 [INFO] nonebot | Waiting for application shutdown.
Shutting down process [140750]...
07-24 23:55:26 [INFO] nonebot | Application shutdown complete.
Stopped reloader.

文件树

➜  universal_bot tree
.
├── adapter-qqguild.config.backup
├── pyproject.toml
├── README.md
└── src
    └── plugins

3 directories, 3 files
➜  universal_bot 
➜  universal_bot cat .env
ENVIRONMENT=dev
DRIVER=~aiohttp



QQGUILD_IS_SANDBOX=true
QQGUILD_BOTS='
[
  {
    "id": "删除",
    "token": "删除",
    "secret": 删除",
    "intent": {
      "guild_messages": true,
      "at_messages": false
    }
  }
]
'

建议火速适配最新群发富媒体消息api端点

关于【机器人发送图片失败】问题处理情况说明
尊敬的各位参赛开发者们:
关于富媒体消息接口更新导致机器人发送图片失败的问题,目前平台已修复。其中主要有以下两个接口更新点需要大家重点关注:
1)两个发消息接口
/v2/groups/{group_openid}/messages,/v2/users/{openid}/messages
新增 msg_type = 7 类型,用作发送富媒体消息,新增 media 字段作为发送内容参数,可结合 msg_id 和 msg_seq 字段使用被动消息的能力。
8279ca053fc7b292c823cce381416a24

  1. 两个富媒体消息接口
    /v2/users/{openid}/files,/v2/groups/{group_openid}/files
    更新使用协议机制
    当请求参数字段 srv_send_msg 设置为 true,会当作【主动消息】直接发送到对应场景,超频会发送失败{"message":"msg limit exceed","code":22009},
    设置成 false 时,请求返回数据用作上述 media 字段作为入参参数内容,开发者可选择使用主动或被动的方式发送到具体的用户或群。
03e4aafe2895ad2d5791ccc1cba779d8

另外如遇其它问题,也欢迎大家联系我们反馈,给大家造成的不便,敬请谅解。目前大赛期间,问题咨询及反馈相对较多,希望大家多多理解,耐心等待。
@全体成员

配置好参数后启动后Bot(type='QQ Guild', self_id='*******') not found in adapter QQ Guild

在安装好此适配器并且在nonebot加载适配器 然后配置好QQGUILD_BOTS等参数后启动nb会一直出现error

08-08 12:36:46 [DEBUG] nonebot | QQ Guild | WebSocket Connection to wss://api.sgroup.qq.com/websocket established
08-08 12:36:46 [ERROR] nonebot | QQ Guild | Error while process data from websocket wss://api.sgroup.qq.com/websocket. Trying to reconnect...
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "D:\Code\Python\python310\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "D:\Code\Python\python310\lib\site-packages\nonebot\drivers\none.py", line 71, in run
    loop.run_until_complete(self._serve())
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 628, in run_until_complete
    self.run_forever()
  File "D:\Code\Python\python310\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 595, in run_forever
    self._run_once()
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 1881, in _run_once
    handle._run()
  File "D:\Code\Python\python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "D:\Code\Python\python310\lib\site-packages\nonebot\adapters\qqguild\adapter.py", line 157, in _forward_ws
    result = await self._authenticate(bot, ws, shard)
  File "D:\Code\Python\python310\lib\site-packages\nonebot\adapters\qqguild\adapter.py", line 269, in _authenticate
    assert isinstance(
AssertionError: Received unexpected payload: InvalidSession(opcode=<Opcode.INVALID_SESSION: 9>, d=False)
08-08 12:36:46 [ERROR] nonebot | QQ Guild | Error while setup websocket to wss://api.sgroup.qq.com/websocket. Trying to reconnect...
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "D:\Code\Python\python310\lib\site-packages\nonebot\__init__.py", line 309, in run
    get_driver().run(*args, **kwargs)
  File "D:\Code\Python\python310\lib\site-packages\nonebot\drivers\none.py", line 71, in run
    loop.run_until_complete(self._serve())
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 628, in run_until_complete
    self.run_forever()
  File "D:\Code\Python\python310\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 595, in run_forever
    self._run_once()
  File "D:\Code\Python\python310\lib\asyncio\base_events.py", line 1881, in _run_once
    handle._run()
  File "D:\Code\Python\python310\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
> File "D:\Code\Python\python310\lib\site-packages\nonebot\adapters\qqguild\adapter.py", line 190, in _forward_ws
    self.bot_disconnect(bot)
  File "D:\Code\Python\python310\lib\site-packages\nonebot\internal\adapter\adapter.py", line 70, in bot_disconnect
    raise RuntimeError(f"{bot} not found in adapter {self.get_name()}")
RuntimeError: Bot(type='QQ Guild', self_id='******') not found in adapter QQ Guild

使用 `Bot` 基类发送文本消息错误

示例

from nonebot.adapters import Bot, Event, Message
from nonebot.adapters.qq import MessageSegment

@best50.handle()
async def _(bot: Bot, event: Event, arg: Message = CommandArg()):
    
    """代码处理"""

    data: Union[BytesIO, str] = test()

    if isinstance(data, BytesIO):
        msg = MessageSegment.file_image(data)
    else:
        msg = data
    print(msg)
    await bot.send(event, msg, reply_message=True)

报错:

找到此玩家请确保此玩家的用户名和查分器中的用户名相同如未绑定请前往查分器官网进行绑定
https://www.diving-fish.com/maimaidx/prober/
10-24 21:42:03 [INFO] nonebot | Matcher(type='message', module=src.plugins.nonebot-plugin-maimaidx.nonebot_plugin_maimaidx, lineno=70) running complete
10-24 21:42:03 [ERROR] nonebot | Running Matcher(type='message', module=src.plugins.nonebot-plugin-maimaidx.nonebot_plugin_maimaidx, lineno=70) failed.
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\Yuzu\.vscode\extensions\ms-python.python-2023.18.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\sakurabot\bot.py", line 15, in <module>
    nonebot.run()
  File "C:\Program Files\Python38\lib\site-packages\nonebot\__init__.py", line 331, in run
    get_driver().run(*args, **kwargs)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\drivers\fastapi.py", line 201, in run
    uvicorn.run(
  File "C:\Program Files\Python38\lib\site-packages\uvicorn\main.py", line 587, in run
    server.run()
  File "C:\Program Files\Python38\lib\site-packages\uvicorn\server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Program Files\Python38\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "C:\Program Files\Python38\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
  File "C:\Program Files\Python38\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
  File "C:\Program Files\Python38\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher
    await _run_matcher(
> File "C:\Program Files\Python38\lib\site-packages\nonebot\message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\internal\matcher\matcher.py", line 846, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\internal\matcher\matcher.py", line 821, in simple_run
    await handler(
  File "C:\Program Files\Python38\lib\site-packages\nonebot\dependencies\__init__.py", line 113, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "C:\sakurabot\src\plugins\nonebot-plugin-maimaidx\nonebot_plugin_maimaidx\__init__.py", line 635, in _
    await bot.send(event, msg, reply_message=True)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\bot.py", line 411, in send
    return await self.send_to_channel(
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\bot.py", line 322, in send_to_channel
    return await self.post_messages(
  File "C:\Program Files\Python38\lib\site-packages\nonebot\internal\adapter\bot.py", line 123, in call_api
    raise exception
  File "C:\Program Files\Python38\lib\site-packages\nonebot\internal\adapter\bot.py", line 98, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\adapter.py", line 415, in _call_api
    return await api_handler(bot, **data)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\utils.py", line 64, in __call__
    return await self.func(inst, *args, **kwds)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\bot.py", line 914, in post_messages
    return parse_obj_as(GuildMessage, await self._request(request))
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\bot.py", line 463, in _request
    return self._handle_response(response)
  File "C:\Program Files\Python38\lib\site-packages\nonebot\adapters\qq\bot.py", line 452, in _handle_response
    raise ActionFailed(response)
nonebot.adapters.qq.exception.ActionFailed: <ActionFailed: 403, code=304003, message=url not allowed, data=None>

datastr 类型的时候,正常应该是使用发送消息的API发送文本消息,但还是使用了发送图片消息的参数,如果 dataBytesIO 使用 MessageSegment.file_image() 发送图片是正常的

适配器每30min自动重连

image
image
适配器每30min都会自动断开连接并进行重连,会影响正在处理的matcher,与腾讯服务器的ws自动重连可否在适配器内部完成

发送QQ群消息时无法发送图片

使用bot.send发送QQ群消息时如果message为

message = MessagSegment.text("测试")+MessageSegment.file_image

则会报错

TypeError: Bot.post_group_messages() got an unexpected keyword argument 'file_image'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.