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.
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.Companion.createDefaultProxied.
Rate limit cancellation
The rate limit can be canceled 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(...) { ... }Content copied to clipboard
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.