YiriMirai
YiriMirai copied to clipboard
使用模型事件总线event为str时报错
Python3.7使用自定义模型事件总线时,执行emit报错; 当传入event为str类型时,会调用super()的emit函数,但此时产生问题为ModelEventBus本身并没有在初始化时调用super()的初始化,且没有提供event_chain_generator,导致ModelEventBus对象不存在event_chain_generator属性;
Traceback (most recent call last):
File "sendmsgEventTest.py", line 143, in thread_listen
await mbus.emit(event, msgs)
File "/usr/local/lib/python3.7/dist-packages/mirai/models/bus.py", line 119, in emit
return await super().emit(event, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/mirai/bus.py", line 187, in emit
for m_event in self.event_chain_generator(event):
AttributeError: 'ModelEventBus' object has no attribute 'event_chain_generator'
ModelEventBus
在即将发布的 0.3 中会废弃,所以这个问题没有修复的必要了。
对旧版本来说,尽量避免这种用法。在新版本中,事件的层级关系将全部由继承表示,原有的按字符串分割的层级将不再可用。