Checks
Checks are decorators that gate command execution. They run before the command callback and can block invocation by raising a CheckError. matrix.py ships with a built-in cooldown check; you can also write custom checks with Registry.add_check.
from matrix import Bot, Context
from matrix.checks import cooldown
bot = Bot()
@bot.command("roll")
@cooldown(rate=1, period=10.0)
async def roll(ctx: Context):
await ctx.reply("🎲 You rolled a 6!")
matrix.checks
cooldown
cooldown(rate, period)
Decorator to cooldown a command.
:param rate: The number of request a user can send. :type rate: int :param period: The period in seconds of the cooldown. :type period: float
Source code in matrix/checks.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |