Skip to content

Limiter API#

LimiterProto #

Bases: Protocol, Generic[ClientT]

A protocol that all limiter hooks should implement. A limiter is simply a special type of hook with added methods.

If you're looking to integrate your own ratelimiter implementation, you should make sure to implement all methods defined here.

Tip

An easy (but not necessary) way to ensure you've implemented all methods is to inherit from this protocol.

__call__ abstractmethod async #

__call__(ctx: Context[ClientT]) -> HookResult

Call the limiter with the given context. Implementations should raise an exception if the limiter is ratelimited or abort via HookResult.

PARAMETER DESCRIPTION
ctx

The context to evaluate the ratelimit under.

TYPE: Context

is_rate_limited abstractmethod #

is_rate_limited(ctx: Context[ClientT]) -> bool

Check if the limiter is rate limited for the given context.

PARAMETER DESCRIPTION
ctx

The context to evaluate the ratelimit under.

TYPE: Context

RETURNS DESCRIPTION
bool

Whether or not the limiter is ratelimited.

reset abstractmethod #

reset(ctx: Context[ClientT]) -> None

Reset the limiter for the given context.

PARAMETER DESCRIPTION
ctx

The context to reset the ratelimit for.

TYPE: Context