lc-cn / onebots

基于icqq的多例oneBot管理应用
https://docs.onebots.org/
MIT License
172 stars 17 forks source link

Onebot V11无法解析上报事件 #168

Closed molanp closed 1 month ago

molanp commented 1 month ago

Nodejs v20

预期效果

10-02 23:58:55 [SUCCESS] nonebot | OneBot V11 3xxx8 | [message.group.normal]: Message 2039027551 from 21xxx0@[群:8xxx185] '[reply:id=2038969363]  🌿🌿'

实际效果

10-02 13:52:13 [SUCCESS] nonebot | OneBot V11 30xxx668 | [message]: {'time': 1727848333, 'self_id': 306xxx8, 'post_type': 'message', 'message': '消息内容', 'message_id': 2991159542809767, 'self': {'platform': 'qq', 'user_id': 3xxx8}, 'rand': 1188260196, 'seq': 30119, 'group_id': 64xxx7, 'atall': False, 'sender': {'user_id': 7xxx19, 'nickname': '群昵称', 'sub_id': 537244893, 'card': '群昵称', 'sex': 'unknown', 'age': 0, 'area': '', 'level': 1, 'role': 'admin', 'title': '开发'}, 'anonymous': None, 'detail_type': 'group', 'group_name': '群', 'block': False, 'sub_type': 'normal', 'type': 'message', 'atme': False, 'font': '宋体', 'id': 'de62kubmos8', 'message_type': 'group', 'alt_message': '消息内容', 'platform': 'qq', 'version': 'V11', 'raw_message': '消息内容', 'user_id': 7xxx19}
10-02 13:52:13 [WARNING] nonebot | Error while parsing command for event
Traceback (most recent call last):

  File "D:\Bot\bot.py", line 30, in <module>
    nonebot.run()
    │       └ <function run at 0x000001B6DE7B8040>
    └ <module 'nonebot' from 'd:\\Runtime\\Python\\3104\\lib\\site-packages\\nonebot\\__init__.py'>

  File "d:\Runtime\Python\3104\lib\site-packages\nonebot\__init__.py", line 335, in run
    get_driver().run(*args, **kwargs)
    │                 │       └ {}
    │                 └ ()
    └ <function get_driver at 0x000001B6DE777AC0>

  File "d:\Runtime\Python\3104\lib\site-packages\nonebot\drivers\fastapi.py", line 186, in run
    uvicorn.run(
    │       └ <function run at 0x000001B6DEF60790>
    └ <module 'uvicorn' from 'd:\\Runtime\\Python\\3104\\lib\\site-packages\\uvicorn\\__init__.py'>

  File "d:\Runtime\Python\3104\lib\site-packages\uvicorn\main.py", line 577, in run
    server.run()
    │      └ <function Server.run at 0x000001B6DEF600D0>
    └ <uvicorn.server.Server object at 0x000001B6A0CF3880>

  File "d:\Runtime\Python\3104\lib\site-packages\uvicorn\server.py", line 65, in run
    return asyncio.run(self.serve(sockets=sockets))
           │       │   │    │             └ None
           │       │   │    └ <function Server.serve at 0x000001B6DEF60160>
           │       │   └ <uvicorn.server.Server object at 0x000001B6A0CF3880>
           │       └ <function run at 0x000001B6DC498A60>
           └ <module 'asyncio' from 'd:\\Runtime\\Python\\3104\\lib\\asyncio\\__init__.py'>

  File "d:\Runtime\Python\3104\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
           │    │                  └ <coroutine object Server.serve at 0x000001B6A0CC9380>
           │    └ <function BaseEventLoop.run_until_complete at 0x000001B6DC59E710>
           └ <ProactorEventLoop running=True closed=False debug=False>

  File "d:\Runtime\Python\3104\lib\asyncio\base_events.py", line 628, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x000001B6DE1D2F80>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "d:\Runtime\Python\3104\lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()

  File "d:\Runtime\Python\3104\lib\asyncio\base_events.py", line 595, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x000001B6DE1701F0>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "d:\Runtime\Python\3104\lib\asyncio\base_events.py", line 1881, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x000001B6DC533BE0>
    └ <Handle <TaskStepMethWrapper object at 0x000001B6A1D64A30>()>

  File "d:\Runtime\Python\3104\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle <TaskStepMethWrapper object at 0x000001B6A1D64A30>()>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle <TaskStepMethWrapper object at 0x000001B6A1D64A30>()>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle <TaskStepMethWrapper object at 0x000001B6A1D64A30>()>

  File "d:\Runtime\Python\3104\lib\site-packages\nonebot\adapters\onebot\v11\bot.py", line 210, in handle_event
    await handle_event(self, event)
          │            │     └ Event(time=1727848333, self_id=30xxx8, post_type='message', message='消息内容', message_id=2991159542809767, self={'platfo...
          │            └ Bot(type='OneBot V11', self_id='3xxxx68')
          └ <function handle_event at 0x000001B6DE8E0550>

> File "d:\Runtime\Python\3104\lib\site-packages\nonebot\message.py", line 524, in handle_event
    TrieRule.get_value(bot, event, state)
    │        │         │    │      └ {'_prefix': {'command': None, 'raw_command': None, 'command_arg': None, 'command_start': None, 'command_whitespace': None}}
    │        │         │    └ Event(time=1727848333, self_id=306xxx68, post_type='message', message='消息内容', message_id=2991159542809767, self={'platfo...
    │        │         └ Bot(type='OneBot V11', self_id='30xxx8')
    │        └ <classmethod(<function TrieRule.get_value at 0x000001B6DE88AF80>)>
    └ <class 'nonebot.rule.TrieRule'>

  File "d:\Runtime\Python\3104\lib\site-packages\nonebot\rule.py", line 101, in get_value
    message = event.get_message()
              │     └ <function Event.get_message at 0x000001B6DEC7DB40>
              └ Event(time=1727848333, self_id=30xxx68, post_type='message', message='消息内容', message_id=2991159542809767, self={'platfo...

  File "d:\Runtime\Python\3104\lib\site-packages\nonebot\adapters\onebot\v11\event.py", line 51, in get_message
    raise ValueError("Event has no message!")

ValueError: Event has no message!

造成后续Matcher无法解析并响应消息

molanp commented 1 month ago

错误原因,发送到ws的数据中,font不是一个有效的整数

molanp commented 1 month ago

修改nonebot源码 adapters/onebot/v11/event.py

153     font: int

153     font: int | str

即可解决