[Core] Fix infinite typing for commands with cooldown (#2987)

* fix(core): cooldown error can't reinvoke command (infinite typing issue)

* chore(changelog): add towncrier entry
This commit is contained in:
jack1142 2019-09-08 01:25:02 +02:00 committed by Michael H
parent 0be3b1acd7
commit cdb7a02cb8
2 changed files with 2 additions and 13 deletions

View File

@ -0,0 +1 @@
Bot no longer types infinitely when command with cooldown is called within last second of cooldown.

View File

@ -232,21 +232,9 @@ def init_events(bot, cli_flags):
elif isinstance(error, commands.NoPrivateMessage): elif isinstance(error, commands.NoPrivateMessage):
await ctx.send("That command is not available in DMs.") await ctx.send("That command is not available in DMs.")
elif isinstance(error, commands.CommandOnCooldown): elif isinstance(error, commands.CommandOnCooldown):
if error.retry_after < 1:
async with ctx.typing():
# the sleep here is so that commands using this for ratelimit purposes
# are not made more lenient than intended, while still being
# more convienient for the user than redoing it less than a second later.
await asyncio.sleep(error.retry_after)
await ctx.bot.invoke(ctx)
# done this way so checks still occur if there are other
# failures possible than just cooldown.
# do not change to ctx.reinvoke()
return
await ctx.send( await ctx.send(
"This command is on cooldown. Try again in {}.".format( "This command is on cooldown. Try again in {}.".format(
humanize_timedelta(seconds=error.retry_after) humanize_timedelta(seconds=error.retry_after) or "1 second"
), ),
delete_after=error.retry_after, delete_after=error.retry_after,
) )