简体   繁体   中英

How do I make my discord python bot recognize response in chat after command?

So in short. I want to made a regular command that makes the bot ask a question and gives an a,b,c answer. I want to make it look for the next message of the person that triggered the command and check the message and see if it's the correct answer.

So I am guessing I have to use the code:

@bot.listen()
async def on_message(message):

Do I compare the person who sent the message to the person the bot is expecting to answer and if so, where would I be best off storing that info?

You guessed wrong, you should use the bot.wait_for method, example

@bot.command()
async def foo(ctx):
    def check(message):
        return message.author == ctx.author

    await ctx.send("whatever")
    message = await bot.wait_for("message", check=check)
    await ctx.send(f"Thanks for the reply! Your message: {message.content}")

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM