GraiaProject / Ariadne

一个优雅且完备的 Python QQ 自动化框架,基于 Mirai API HTTP v2。 Powered by Graia Project.
https://graia.cn/ariadne
GNU Affero General Public License v3.0
746 stars 45 forks source link

AttributeError: 'XXXEvent' object has no attribute '[group|member|...]'[Bug] #83

Closed SAGIRI-kawaii closed 2 years ago

SAGIRI-kawaii commented 2 years ago

问题 多个事件报错 AttributeError: 'XXXEvent' object has no attribute '[group|member|...]'

如何复现 尝试以下代码:

@bcc.receiver(MemberLeaveEventKick)
async def test(group: Group, event: MemberLeaveEventKick):
    print(group.id, event)

发生如日志中错误

预期行为 你希望如何更改/原本应该是怎样的.

使用环境:

日志/截图 将任何有关的日志/截图放到这里(控制台输出/MAH 输出/...)

2022-01-21 11:00:42.584 | ERROR    | graia.ariadne.util:loguru_excepthook:97 - Exception:
Traceback (most recent call last):

  File "W:/Python workspace/RE-SAGIRIBOT\main.py", line 70, in <module>
    core.launch()
    │    └ <function AppCore.launch at 0x0000021B8A0324C0>
    └ <sagiri_bot.core.app_core.AppCore object at 0x0000021BF08185E0>

  File "W:\Python workspace\RE-SAGIRIBOT\sagiri_bot\core\app_core.py", line 127, in launch
    self.__app.launch_blocking()
    └ <sagiri_bot.core.app_core.AppCore object at 0x0000021BF08185E0>

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\ariadne\app.py", line 1463, in launch_blocking
    self.loop.run_until_complete(self.lifecycle())
    │    │    │                  │    └ <function Ariadne.lifecycle at 0x0000021B896D7CA0>
    │    │    │                  └ <graia.ariadne.app.Ariadne object at 0x0000021B8A043FD0>
    │    │    └ <function BaseEventLoop.run_until_complete at 0x0000021BFFF87AF0>
    │    └ <ProactorEventLoop running=True closed=False debug=False>
    └ <graia.ariadne.app.Ariadne object at 0x0000021B8A043FD0>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x0000021B88B64160>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x0000021BFFF8C5E0>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x0000021BFFF2D3A0>
    └ <Handle <TaskStepMethWrapper object at 0x0000021BC9B3DC70>()>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle <TaskStepMethWrapper object at 0x0000021BC9B3DC70>()>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle <TaskStepMethWrapper object at 0x0000021BC9B3DC70>()>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle <TaskStepMethWrapper object at 0x0000021BC9B3DC70>()>

> File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\broadcast\__init__.py", line 147, in Executor
    parameter_compile_result[name] = await dii.lookup_param(name, annotation, default, optimized_log)
    │                        │             │   │            │     │           │        └ [<class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>]
    │                        │             │   │            │     │           └ None
    │                        │             │   │            │     └ <class 'graia.ariadne.model.Group'>
    │                        │             │   │            └ 'group'
    │                        │             │   └ <function DispatcherInterface.lookup_param at 0x0000021B88C76310>
    │                        │             └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x0000021B8A043E50>
    │                        └ 'group'
    └ {'app': <graia.ariadne.app.Ariadne object at 0x0000021B8A043FD0>}

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\broadcast\interfaces\dispatcher.py", line 88, in lookup_param
    result = await getattr(dispatcher, "catch", dispatcher)(self)  # type: ignore
                           │                    │           └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x0000021B8A043E50>
                           │                    └ <class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>
                           └ <class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\ariadne\event\mirai.py", line 287, in catch
    return interface.event.group
           │         └ <property object at 0x0000021B88C72540>
           └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x0000021B8A043E50>

AttributeError: 'MemberLeaveEventKick' object has no attribute 'group'
GreyElaina commented 2 years ago

请求 type(interface.event) 的内容

SAGIRI-kawaii commented 2 years ago

请求 type(interface.event) 的内容

GroupRecallEvent 事件下加入 print(type(interface.event)) 后,当收到 MemberJoinEvent 时发生报错(graia.ariadne.event.mirai line 286) 打印信息如下:

<class 'graia.ariadne.event.mirai.GroupRecallEvent'>
<class 'graia.ariadne.event.mirai.GroupRecallEvent'>
<class 'graia.ariadne.event.mirai.MemberJoinEvent'>

报错信息如下:

2022-01-21 17:00:03.875 | ERROR    | graia.ariadne.util:loguru_excepthook:97 - Exception:
Traceback (most recent call last):

  File "W:/Python workspace/RE-SAGIRIBOT\main.py", line 70, in <module>
    core.launch()
    │    └ <function AppCore.launch at 0x000002186CB934C0>
    └ <sagiri_bot.core.app_core.AppCore object at 0x00000218533785E0>

  File "W:\Python workspace\RE-SAGIRIBOT\sagiri_bot\core\app_core.py", line 127, in launch
    self.__app.launch_blocking()
    └ <sagiri_bot.core.app_core.AppCore object at 0x00000218533785E0>

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\ariadne\app.py", line 1463, in launch_blocking
    self.loop.run_until_complete(self.lifecycle())
    │    │    │                  │    └ <function Ariadne.lifecycle at 0x000002186C237CA0>
    │    │    │                  └ <graia.ariadne.app.Ariadne object at 0x000002186CBA3F40>
    │    │    └ <function BaseEventLoop.run_until_complete at 0x000002186B307AF0>
    │    └ <ProactorEventLoop running=True closed=False debug=False>
    └ <graia.ariadne.app.Ariadne object at 0x000002186CBA3F40>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 603, in run_until_complete
    self.run_forever()
    │    └ <function ProactorEventLoop.run_forever at 0x000002186B6C4160>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 570, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x000002186B30B5E0>
    └ <ProactorEventLoop running=True closed=False debug=False>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\base_events.py", line 1859, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x000002186B2AD3A0>
    └ <Handle <TaskStepMethWrapper object at 0x0000021818976F10>()>

  File "S:\Anaconda3\envs\ariadne\lib\asyncio\events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle <TaskStepMethWrapper object at 0x0000021818976F10>()>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle <TaskStepMethWrapper object at 0x0000021818976F10>()>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle <TaskStepMethWrapper object at 0x0000021818976F10>()>

> File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\broadcast\__init__.py", line 147, in Executor
    parameter_compile_result[name] = await dii.lookup_param(name, annotation, default, optimized_log)
    │                        │             │   │            │     │           │        └ [<class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>]
    │                        │             │   │            │     │           └ None
    │                        │             │   │            │     └ <class 'graia.ariadne.model.Group'>
    │                        │             │   │            └ 'group'
    │                        │             │   └ <function DispatcherInterface.lookup_param at 0x000002186B7D6310>
    │                        │             └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x000002186CBA3DC0>
    │                        └ 'group'
    └ {'app': <graia.ariadne.app.Ariadne object at 0x000002186CBA3F40>}

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\broadcast\interfaces\dispatcher.py", line 88, in lookup_param
    result = await getattr(dispatcher, "catch", dispatcher)(self)  # type: ignore
                           │                    │           └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x000002186CBA3DC0>
                           │                    └ <class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>
                           └ <class 'graia.ariadne.event.mirai.GroupRecallEvent.Dispatcher'>

  File "S:\Anaconda3\envs\ariadne\lib\site-packages\graia\ariadne\event\mirai.py", line 288, in catch
    return interface.event.group
           │         └ <property object at 0x000002186B7D0590>
           └ <graia.broadcast.interfaces.dispatcher.DispatcherInterface object at 0x000002186CBA3DC0>

AttributeError: 'MemberJoinEvent' object has no attribute 'group'

值得注意的是在错误追溯中本应追溯到 MemberJoinEventcatch 函数,结果却追溯到了 GroupRecallEventcatch 函数