Cooldown For On_message In Discord.py
I have made a Leveling system but i can't figure out to make a cooldown in on_message i want to add a BucketType.member cooldown and as im using MondoDB for database so i can't aff
Solution 1:
You should use CooldownMapping.from_cooldown
to add cooldowns to the on_message
event, example:
import typing
import discord
from discord.ext import commands
class SomeCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
self._cd = commands.CooldownMapping.from_cooldown(1, 6.0, commands.BucketType.member) # Change accordingly
# rate, per, BucketType
def get_ratelimit(self, message: discord.Message) -> typing.Optional[int]:
"""Returns the ratelimit left"""
bucket = self._cd.get_bucket(message)
return bucket.update_rate_limit()
@commands.Cog.listener()
async def on_message(self, message):
if "check something":
# Getting the ratelimit left
ratelimit = self.get_ratelimit(message)
if ratelimit is None:
# The user is not ratelimited, you can add the XP or level up the user here
else:
# The user is ratelimited
Post a Comment for "Cooldown For On_message In Discord.py"