diff options
| author | 2020-06-10 15:53:33 -0500 | |
|---|---|---|
| committer | 2020-06-10 15:53:33 -0500 | |
| commit | b71ff0f2bbd7be64d1a0009b9e6530ba3c179926 (patch) | |
| tree | ccc338585a6368117269e2893e1359e35ef0d508 | |
| parent | Rename to customcooldown.md (diff) | |
Update example to not be in a cog
| -rw-r--r-- | bot/resources/tags/customcooldown.md | 22 | 
1 files changed, 10 insertions, 12 deletions
| diff --git a/bot/resources/tags/customcooldown.md b/bot/resources/tags/customcooldown.md index 3d34c078b..35f28a1e5 100644 --- a/bot/resources/tags/customcooldown.md +++ b/bot/resources/tags/customcooldown.md @@ -1,22 +1,20 @@  **Cooldowns** -Cooldowns are used in discord.py to rate-limit. +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 -class SomeCog(commands.Cog): -    def __init__(self): -        self._cd = commands.CooldownMapping.from_cooldown(1.0, 60.0, commands.BucketType.user) +_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 +async def on_message(message): +    bucket = _cd.get_bucket(message) +    retry_after = bucket.update_rate_limit() +    if retry_after: +        await message.channel.send("Slow down! You're sending messages too fast") +        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). | 
