nonebot / nonebot2

跨平台 Python 异步聊天机器人框架 / Asynchronous multi-platform chatbot framework written in Python
https://nonebot.dev
MIT License
5.9k stars 555 forks source link

连接LLOneBot后无法正常发送消息 #2757

Closed A-n-k-a closed 3 months ago

A-n-k-a commented 3 months ago

操作系统

Windows

Python 版本

3.11.8

NoneBot 版本

2.3.1

适配器

OneBot11 2.4.3

协议端

LLOneBot 3.26.5

描述问题

正向ws和反向ws均尝试过连接,且现象相同: 不安装任何插件时,在运行日志中看到所有消息接收均正常,一旦安装了插件且消息触发了插件回复就会报错“发送超时”,但实际上,当消息是文本且文本字数较少时能够在QQ上看到消息确实发出来了,而当文本较长或是图片、音频等除文本以外的消息时,报错相同,而QQ中看不到消息。

复现步骤

nonebot的安装遵照文档进行。 LLOneBot的安装也完全遵照其文档进行。 反向ws使用nonebot文档中的配置

HOST=0.0.0.0  # 配置 NoneBot 监听的 IP / 主机名
PORT=8080  # 配置 NoneBot 监听的端口

正向ws使用onebot适配器文档中的配置 ONEBOT_WS_URLS=["ws://127.0.0.1:6700"] 对应的LLOneBot配置如下图

image

配置完成后启动nonebot,看到日志输出协议端连接成功,然后在QQ中发送指令,之后就出现报错。 在之后不断的尝试中发现虽然报错,但QQ中能收到短文本消息,收不到长文本或图片、音频等特殊类型的消息。

期望的结果

正常发送各类消息(包括但不限于文本、图片、语音等)

截图或日志

报错时的日志:

06-08 22:06:15 [INFO] nonebot | Matcher(type='message', module=nonebot_plugin_roll, lineno=28) running complete
06-08 22:06:15 [ERROR] nonebot | Running Matcher(type='message', module=nonebot_plugin_roll, lineno=28) failed.
Traceback (most recent call last):
  File "<string>", line 15, in <module>
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\__init__.py", line 335, in run
    get_driver().run(*args, **kwargs)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\drivers\fastapi.py", line 186, in run
    uvicorn.run(
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\uvicorn\main.py", line 577, in run
    server.run()
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\uvicorn\server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 641, 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 608, in run_forever
    self._run_once()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1936, in _run_once
    handle._run()
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\asyncio\events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\message.py", line 476, in check_and_run_matcher
    await _run_matcher(
> File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\message.py", line 428, in _run_matcher
    await matcher.run(bot, event, state, stack, dependency_cache)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 850, in run
    await self.simple_run(bot, event, state, stack, dependency_cache)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 825, in simple_run
    await handler(
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\dependencies\__init__.py", line 94, in __call__
    return await cast(Callable[..., Awaitable[R]], self.call)(**values)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot_plugin_roll\__init__.py", line 106, in _
    await matcher.finish(f"你掷出了{dice_num}个{dice_side}面骰子, 点数为【{dice_result}】")
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 582, in finish
    await cls.send(message, **kwargs)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\matcher\matcher.py", line 566, in send
    return await bot.send(event=event, message=_message, **kwargs)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 228, in send
    return await self.__class__.send_handler(self, event, message, **kwargs)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 181, in send
    return await bot.send_msg(**params)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 122, in call_api
    raise exception
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\internal\adapter\bot.py", line 97, in call_api
    result = await self.adapter._call_api(self, api, **data)
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\adapters\onebot\v11\adapter.py", line 147, in _call_api
    return handle_api_result(await self._result_store.fetch(seq, timeout))
  File "D:\Portable-Program-Files\nonebot\LLOneBot\.venv\Lib\site-packages\nonebot\adapters\onebot\v11\utils.py", line 58, in handle_api_result
    raise ActionFailed(**result)
nonebot.adapters.onebot.v11.exception.ActionFailed: ActionFailed(status='failed', retcode=1200, data=None, message='发送超时', wording='发送超时', echo='1')

LiteLoader版本信息及扩展安装情况截图: image

yanyongyu commented 3 months ago

这个报错内容是llob返回给nb的,不是nb产生的,你应该找llob

A-n-k-a commented 3 months ago

我确认D:\Portable-Program-Files\nonebot\LLOneBot这个路径是我安装nonebot的路径,不是LLOneBot的路径,只是我给nonebot设置的项目名称是LLOneBot,应该就是nonebot的报错,LLOneBot没有.venv这样的虚拟环境,而且LLOneBot不是Python写的,报错也不应该是这个格式的。 补充一下刚刚重新测试时的LLOneBot端日志:

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"self_id":<机器人QQ号>,"user_id":<用户QQ号>,"time":1717897432,"message_id":-2147482813,"real_id":-2147482813,"message_seq":-2147482813,"message_type":"group","sender":{"user_id":<用户QQ号>,"nickname":"꧁不̶死̶鸟̶A̶n̶k̶a̶༼༽","card":"","role":"admin"},"raw_message":"rd 3d6","font":14,"sub_type":"normal","message":[{"data":{"text":"rd 3d6"},"type":"text"}],"message_format":"array","post_type":"message","group_id":<QQ群号>} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"self_id":<机器人QQ号>,"user_id":<用户QQ号>,"time":1717897432,"message_id":-2147482813,"real_id":-2147482813,"message_seq":-2147482813,"message_type":"group","sender":{"user_id":<用户QQ号>,"nickname":"꧁不̶死̶鸟̶A̶n̶k̶a̶༼༽","card":"","role":"admin"},"raw_message":"rd 3d6","font":14,"sub_type":"normal","message":[{"data":{"text":"rd 3d6"},"type":"text"}],"message_format":"array","post_type":"message","group_id":<QQ群号>} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 收到反向Websocket消息 {"action":"send_msg","params":{"user_id":<用户QQ号>,"group_id":<QQ群号>,"message_type":"group","message":[{"type":"text","data":{"text":"你掷出了3个6面骰子, 点数为【8】"}}]},"echo":"7"} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 发送消息总大小 0 bytes 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 设置消息超时时间 5000 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:53 亚托莉(<机器人QQ号>): message update 7452530323665934133 {"msgId":"7452530323665934133","msgRandom":"52703154","msgSeq":"9335","cntSeq":"0","chatType":2,"msgType":2,"subMsgType":1,"sendType":1,"senderUid":"u_LeZEYWgzMlwucnn88gnoJA","peerUid":"<QQ群号>","channelId":"","guildId":"undefined","guildCode":"0","fromUid":"0","fromAppid":"0","msgTime":"1717897432","msgMeta":"0x","sendStatus":2,"sendRemarkName":"","sendMemberName":"","sendNickName":"亚托莉","guildName":"","channelName":"","elements":[{"elementType":1,"elementId":"7378313290322406462","extBufForUI":"0x","textElement":{"content":"你掷出了3个6面骰子, 点数为【8】","atType":0,"atUid":"0","atTinyId":"0","atNtUid":"","subElementType":0,"atChannelId":"0","linkInfo":null,"atRoleId":"0","atRoleColor":0,"atRoleName":"","needNotify":0},"faceElement":null,"marketFaceElement":null,"replyElement":null,"picElement":null,"pttElement":null,"videoElement":null,"grayTipElement":null,"arkElement":null,"fileElement":null,"liveGiftElement":null,"markdownElement":null,"structLongMsgElement":null,"multiForwardMsgElement":null,"giphyElement":null,"walletElement":null,"inlineKeyboardElement":null,"textGiftElement":null,"calendarElement":null,"yoloGameResultElement":null,"avRecordElement":null,"structMsgElement":null,"faceBubbleElement":null,"shareLocationElement":null,"tofuRecordElement":null,"taskTopMsgElement":null,"recommendedMsgElement":null,"actionBarElement":null}],"records":[],"emojiLikesList":[],"commentCnt":"0","directMsgFlag":0,"directMsgMembers":[],"peerName":"小Anka、小小不死鸟~","freqLimitInfo":null,"editable":true,"avatarMeta":"","avatarPendant":"","feedId":"","roleId":"0","timeStamp":"0","clientIdentityInfo":null,"isImportMsg":false,"atType":0,"roleType":0,"fromChannelRoleInfo":{"roleId":"0","name":"","color":0},"fromGuildRoleInfo":{"roleId":"0","name":"","color":0},"levelRoleInfo":{"roleId":"0","name":"","color":0},"recallTime":"0","isOnlineMsg":false,"generalFlags":"0x","clientSeq":"9731","fileGroupSize":null,"foldingInfo":null,"multiTransInfo":null,"senderUin":"<机器人QQ号>","peerUin":"<QQ群号>","msgAttrs":{},"anonymousExtInfo":null,"nameType":0,"avatarFlag":0,"extInfoForUI":null,"personalMedal":null,"categoryManage":0,"msgEventInfo":null} 

2024/6/9 09:43:53 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897433,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

nonebote端报错信息与之前那个相同。

RF-Tar-Railt commented 3 months ago

我确认D:\Portable-Program-Files\nonebot\LLOneBot这个路径是我安装nonebot的路径,不是LLOneBot的路径,只是我给nonebot设置的项目名称是LLOneBot,应该就是nonebot的报错,LLOneBot没有.venv这样的虚拟环境,而且LLOneBot不是Python写的,报错也不应该是这个格式的。 补充一下刚刚重新测试时的LLOneBot端日志:

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"self_id":<机器人QQ号>,"user_id":<用户QQ号>,"time":1717897432,"message_id":-2147482813,"real_id":-2147482813,"message_seq":-2147482813,"message_type":"group","sender":{"user_id":<用户QQ号>,"nickname":"꧁不̶死̶鸟̶A̶n̶k̶a̶༼༽","card":"","role":"admin"},"raw_message":"rd 3d6","font":14,"sub_type":"normal","message":[{"data":{"text":"rd 3d6"},"type":"text"}],"message_format":"array","post_type":"message","group_id":<QQ群号>} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"self_id":<机器人QQ号>,"user_id":<用户QQ号>,"time":1717897432,"message_id":-2147482813,"real_id":-2147482813,"message_seq":-2147482813,"message_type":"group","sender":{"user_id":<用户QQ号>,"nickname":"꧁不̶死̶鸟̶A̶n̶k̶a̶༼༽","card":"","role":"admin"},"raw_message":"rd 3d6","font":14,"sub_type":"normal","message":[{"data":{"text":"rd 3d6"},"type":"text"}],"message_format":"array","post_type":"message","group_id":<QQ群号>} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 收到反向Websocket消息 {"action":"send_msg","params":{"user_id":<用户QQ号>,"group_id":<QQ群号>,"message_type":"group","message":[{"type":"text","data":{"text":"你掷出了3个6面骰子, 点数为【8】"}}]},"echo":"7"} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 发送消息总大小 0 bytes 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): 设置消息超时时间 5000 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:52 亚托莉(<机器人QQ号>): ws 消息上报  {"time":1717897432,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

2024/6/9 09:43:53 亚托莉(<机器人QQ号>): message update 7452530323665934133 {"msgId":"7452530323665934133","msgRandom":"52703154","msgSeq":"9335","cntSeq":"0","chatType":2,"msgType":2,"subMsgType":1,"sendType":1,"senderUid":"u_LeZEYWgzMlwucnn88gnoJA","peerUid":"<QQ群号>","channelId":"","guildId":"undefined","guildCode":"0","fromUid":"0","fromAppid":"0","msgTime":"1717897432","msgMeta":"0x","sendStatus":2,"sendRemarkName":"","sendMemberName":"","sendNickName":"亚托莉","guildName":"","channelName":"","elements":[{"elementType":1,"elementId":"7378313290322406462","extBufForUI":"0x","textElement":{"content":"你掷出了3个6面骰子, 点数为【8】","atType":0,"atUid":"0","atTinyId":"0","atNtUid":"","subElementType":0,"atChannelId":"0","linkInfo":null,"atRoleId":"0","atRoleColor":0,"atRoleName":"","needNotify":0},"faceElement":null,"marketFaceElement":null,"replyElement":null,"picElement":null,"pttElement":null,"videoElement":null,"grayTipElement":null,"arkElement":null,"fileElement":null,"liveGiftElement":null,"markdownElement":null,"structLongMsgElement":null,"multiForwardMsgElement":null,"giphyElement":null,"walletElement":null,"inlineKeyboardElement":null,"textGiftElement":null,"calendarElement":null,"yoloGameResultElement":null,"avRecordElement":null,"structMsgElement":null,"faceBubbleElement":null,"shareLocationElement":null,"tofuRecordElement":null,"taskTopMsgElement":null,"recommendedMsgElement":null,"actionBarElement":null}],"records":[],"emojiLikesList":[],"commentCnt":"0","directMsgFlag":0,"directMsgMembers":[],"peerName":"小Anka、小小不死鸟~","freqLimitInfo":null,"editable":true,"avatarMeta":"","avatarPendant":"","feedId":"","roleId":"0","timeStamp":"0","clientIdentityInfo":null,"isImportMsg":false,"atType":0,"roleType":0,"fromChannelRoleInfo":{"roleId":"0","name":"","color":0},"fromGuildRoleInfo":{"roleId":"0","name":"","color":0},"levelRoleInfo":{"roleId":"0","name":"","color":0},"recallTime":"0","isOnlineMsg":false,"generalFlags":"0x","clientSeq":"9731","fileGroupSize":null,"foldingInfo":null,"multiTransInfo":null,"senderUin":"<机器人QQ号>","peerUin":"<QQ群号>","msgAttrs":{},"anonymousExtInfo":null,"nameType":0,"avatarFlag":0,"extInfoForUI":null,"personalMedal":null,"categoryManage":0,"msgEventInfo":null} 

2024/6/9 09:43:53 亚托莉(<机器人QQ号>): ws 消息上报 ws://127.0.0.1:8081/onebot/v11/ws/ {"time":1717897433,"self_id":<机器人QQ号>,"post_type":"meta_event","meta_event_type":"heartbeat","status":{"online":true,"good":true},"interval":1000} 

nonebote端报错信息与之前那个相同。

你没听懂吗,"发送超时",这个错误信息是来自api请求的响应的状态码

你要是不知道什么叫做ob的接口状态码,建议直接去llob问linyuchen

A-n-k-a commented 3 months ago

好的,已在LLOneBot仓库提出issue #252