Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

Discord.py client.wait_for() sends multiple messages

I am making a discord bot with rewrite, but when my command runs, SOMETIMES sends all the messages at once, sometimes works well. Anyone knows why? I'm struggling with this a long time

@client.event
async def on_message(message):
    if message.content.startswith("!order"):
        channel = message.channel
        await channel.send("in game name")
        in_game_name = await client.wait_for('message', check=None)

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

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

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

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

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

Upvotes: 0

Views: 720

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60974

You can create a check function that only checks that the message is in the correct channel and was not sent by the 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.channel
        await channel.send("in game name")
        in_game_name = await client.wait_for('message', check=check)
        ...

Upvotes: 2

Related Questions