aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Mark <[email protected]>2020-06-17 12:31:09 -0700
committerGravatar GitHub <[email protected]>2020-06-17 12:31:09 -0700
commita8c43a4fabfbf3214fb0405b48442bf8be4a77e0 (patch)
treea08adbe3fcb5d8510691358a1b60730b9c4b561d
parentMerge pull request #1001 from python-discord/bug/mod/bot-68/ban-strips-none (diff)
parentUpdate bot/resources/tags/customcooldown.md (diff)
Merge pull request #991 from crazygmr101/feature/cooldown-tag
Create cooldown.md
-rw-r--r--bot/resources/tags/customcooldown.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md
new file mode 100644
index 000000000..ac7e70aee
--- /dev/null
+++ b/bot/resources/tags/customcooldown.md
@@ -0,0 +1,20 @@
+**Cooldowns in discord.py**
+
+Cooldowns can be used in discord.py to rate-limit. In this example, we're using it in an on_message.
+
+```python
+from discord.ext import commands
+
+message_cooldown = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user)
+
+async def on_message(message):
+ bucket = message_cooldown.get_bucket(message)
+ retry_after = bucket.update_rate_limit()
+ if retry_after:
+ await message.channel.send(f"Slow down! Try again in {retry_after} seconds.")
+ else:
+ await message.channel.send("Not ratelimited!")
+```
+
+`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`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.discord.ext.commands.BucketType).