Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

discord.py-rewrite wait_for() cancel

I am making a discord bot with rewrite, when the command runs, the event must finish, but if I want to execute another command I can't beacase the previous one it's not finished and It will send the other messages, how can I stop that?

@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)

Upvotes: 0

Views: 468

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60974

You could raise an exception in your check if it sees a certain word. Here, if the bot sees the message CANCEL it will cancel the command:

@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)

Upvotes: 1

Related Questions