rateLimit

abstract fun rateLimit(rateLimiter: RateLimiter, block: RateLimitBuilder.() -> Unit = {})(source)

Sets an anonymous rate limiter on this command. This rate limiter cannot be referenced anywhere else as it is not registered.

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

Rate limit cancellation

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

Example

@Command
class SlashSkip : GlobalApplicationCommandProvider {
suspend fun onSlashSkip(event: GuildSlashEvent) {
// Handle command
}

override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) {
manager.slashCommand("skip", function = ::onSlashSkip) {
val bucketConfiguration = Buckets.spikeProtected(
capacity = 5,
duration = 1.minutes,
spikeCapacity = 2,
spikeDuration = 5.seconds
)

rateLimit(RateLimiter.createDefault(RateLimitScope.USER, bucketConfiguration.toSupplier(), deleteOnRefill = true))
}
}
}

Parameters

rateLimiter

The RateLimiter in charge of retrieving buckets and handling rate limits

block

Further configures the RateLimitBuilder

See also