我想为每个事件运行特定的代码块。我想如果有类似on_any_event
的东西,那可能是最简单的.但是,我似乎在文档或网络上找不到任何内容。有谁知道是否有办法做到这一点,如果有,如何?
其他信息:
- discord.py 重写
提前谢谢。
我看到两种可能性:
discord.py afaik 中的大多数事件都是套接字响应的"处理程序"。 您可以尝试使用on_socket_response(message)
事件。对于所有基于 websocket 的事件来说,这应该足够了。
如果你需要任何事件,你可以尝试覆盖子类中的dispatch
函数,并将这个类用作机器人的类。 例如:
from discord.ext import commands
class MyBot(commands.Bot):
def dispatch(self, event_name, *args, **kwargs):
super().dispatch("event", event_name)
super().dispatch(event_name, *args, **kwargs)
bot = MyBot(command_prefix="!")
这将在任何事件上调度其他事件
@bot.event
async def on_event(event_name):
print(f"{event_name} is dispatched")