RateLimit

annotation class RateLimit(val scope: RateLimitScope, val deleteOnRefill: Boolean = true, val bandwidths: Bandwidth)(source)

Defines a rate limit for a command / component handler.

Note: This won't apply if you are a bot owner.

Text commands note: This applies to the command itself, not only this variation, in other words, this applies to all commands with the same path.

Persistent bucket storage

Since this annotation stores buckets in-memory by default, the rate limits applied will be lost upon restart, however you can implement AnnotatedRateLimiterFactory in a service, and then uses your own ProxyManager which stores your buckets in persistent storage, alongside RateLimiter.createDefaultProxied.

Rate limit cancellation

The rate limit can be cancelled inside the command with CancellableRateLimit.cancelRateLimit on your event.

Example

@RateLimit(
scope = RateLimitScope.USER, bandwidths = {
@Bandwidth(capacity = 5, refill = @Refill(type = RefillType.GREEDY, tokens = 5, period = 1, periodUnit = ChronoUnit.MINUTES)),
@Bandwidth(capacity = 2, refill = @Refill(type = RefillType.INTERVAL, tokens = 2, period = 5, periodUnit = ChronoUnit.SECONDS))
})
@JDASlashCommand(...)
public void onSlashRateLimit(...) { ... }

See also

Properties

Link copied to clipboard
Link copied to clipboard

Whether the rate limit message should be deleted after the rate limit has expired.

Link copied to clipboard

Scope of the rate limit, see RateLimitScope values.