diff options
| author | Dan Hess <[email protected]> | 2020-08-05 20:37:08 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-05 21:37:08 -0400 |
| commit | 3a9fd00a1adea76c0821b958b56dbf83e6f19b36 (patch) | |
| tree | 5b373e4c9759884f221e5746d79f20cfb0f297a6 /discord/ext/commands/cooldowns.py | |
| parent | [commands] Restart subcommand_passed chain on invoke (diff) | |
| download | discord.py-3a9fd00a1adea76c0821b958b56dbf83e6f19b36.tar.xz discord.py-3a9fd00a1adea76c0821b958b56dbf83e6f19b36.zip | |
[commands] Provide a way to retrieve time left for a cooldown
Diffstat (limited to 'discord/ext/commands/cooldowns.py')
| -rw-r--r-- | discord/ext/commands/cooldowns.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/discord/ext/commands/cooldowns.py b/discord/ext/commands/cooldowns.py index 08f36b60..c530bb12 100644 --- a/discord/ext/commands/cooldowns.py +++ b/discord/ext/commands/cooldowns.py @@ -91,6 +91,15 @@ class Cooldown: tokens = self.rate return tokens + def get_retry_after(self, current=None): + current = current or time.time() + tokens = self.get_tokens(current) + + if tokens == 0: + return self.per - (current - self._window) + + return 0.0 + def update_rate_limit(self, current=None): current = current or time.time() self._last = current |