Reputation: 11
I'm trying to build a discord bot which should wait for an user input for 5s. If the input is given it should respond with "on time" and if the input is not given it should say "too late".
The problem with my code is that I always end up on the "too late" even if a give an input. After 5s it send always the "too late". Does anyone knows what I'm doing wrong? :) Thanks for your help!
try:
msg = await bot.wait_for("msg",timeout=5)
if msg:
await ctx.send("on time!")
except asyncio.TimeoutError:
await ctx.send("Too late!")
Upvotes: 1
Views: 2154
Reputation: 1639
Based on Lukasz and metro's comments, here's what your code should look like:
try:
msg = await bot.wait_for("message", check=lambda message: message.author == ctx.author, timeout=5)
if msg:
await ctx.send("on time!")
except asyncio.TimeoutError:
await ctx.send("Too late!")
Upvotes: 2