aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Daniel Nash <[email protected]>2020-06-07 03:15:51 -0500
committerGravatar GitHub <[email protected]>2020-06-07 03:15:51 -0500
commit8570bd2c9d644c82e69e4c3bbae3af24f95180e2 (patch)
tree8e612d39bd8be334e724e2c1f178cb414d5e382e
parentEnable the 'redis' / 'aiohttp' Sentry integrations (diff)
Create cooldown.md
-rw-r--r--bot/resources/tags/cooldown.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/resources/tags/cooldown.md b/bot/resources/tags/cooldown.md
new file mode 100644
index 000000000..a4e237872
--- /dev/null
+++ b/bot/resources/tags/cooldown.md
@@ -0,0 +1,22 @@
+**Cooldowns**
+
+Cooldowns are used in discord.py to rate-limit.
+
+```python
+from discord.ext import commands
+
+class SomeCog(commands.Cog):
+ def __init__(self):
+ self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user)
+
+ async def cog_check(self, ctx):
+ bucket = self._cd.get_bucket(ctx.message)
+ retry_after = bucket.update_rate_limit()
+ if retry_after:
+ # you're rate limited
+ # helpful message here
+ pass
+ # you're not rate limited
+```
+
+`from_cooldown` takes the amount of `update_rate_limit()`s needed to trigger the cooldown, the time in which the cooldown is triggered, and a [`BucketType`](discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType).