您可以等待 discord.py 中的多个事件吗?

can you wait for multiple events in discord.py?

我正在尝试为我的机器人等待多个事件,我确实找到了一种方法并且它有效,但突然间它无缘无故地崩溃了

while True:
    done, pending = await asyncio.wait(
        [
            bot.wait_for("raw_reaction_add")
            bot.wait_for("raw_reacion_remove")
        ]
    )

    payload = done.pop().result()
    if payload.event_type == "REACTION_ADD":
        ...
    elif payload.event_type == "REACTION_REMOVE":
        ...

    for future in pending:
        future.cancel()

在我的主命令中这样做是行不通的,但我做了一个测试命令,一切都是一样的,它没有任何问题

您可以使用 on_reaction_addon_reacion_remove 的正常机器人事件或它们的原始版本来完成此操作。要在彼此之间共享数据,您可以使用 MongoDB/pymongo 或 MySQL/sqlite.

等数据库

如果您将此命令用于反应角色,那么数据库将是与主要机器人事件一起使用的更好选择。

这将使以后的调试变得更加容易。