discord.py-rewrite wait_for()取消

时间:2020-05-04 17:05:55

标签: python discord.py discord.py-rewrite

我正在通过重写制作一个不和谐的bot,当该命令运行时,该事件必须完成,但是如果我想执行另一条命令,则无法等待上一条命令未完成,它将发送其他消息,如何我可以停止吗?

@client.event
async def on_message(message):
    def check(m):
        return m.channel == message.channel and m.author != client.user

    if message.content.startswith("!order"):
        channel = message.author
        await channel.send("in game name")
        in_game_name = await client.wait_for('message', check=check)

        await channel.send("in game ID")
        in_game_ID = await client.wait_for('message', check=check)

        await channel.send("cargo type")
        cargo_type = await client.wait_for('message', check=check)

        await channel.send("cargo limit")
        cargo_limit = await client.wait_for('message', check=check)

        await channel.send("storage")
        storage = await client.wait_for('message', check=check)

        await channel.send("priority")
        priority = await client.wait_for('message', check=check)

1 个答案:

答案 0 :(得分:1)

如果检查中看到某个单词,则可以在检查中引发异常。在这里,如果漫游器看到消息CANCEL,它将取消命令:

@client.event
async def on_message(message):
    def check(m):
        if m.channel == message.channel and m.content == "CANCEL":
            raise ValueError("Cancelled command")
        return m.channel == message.channel and m.author != client.user

    if message.content.startswith("!order"):
        channel = message.author
        await channel.send("in game name")
        in_game_name = await client.wait_for('message', check=check)