rateLimit

abstract fun rateLimit(bucketFactory: BucketFactory, limiterFactory: RateLimiterFactory = RateLimiter.defaultFactory(RateLimitScope.USER), 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.

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 bucketFactory = BucketFactory.spikeProtected(
capacity = 5,
duration = 1.minutes,
spikeCapacity = 2,
spikeDuration = 5.seconds
)

// Defaults to the USER rate limit scope
rateLimit(bucketFactory)
}
}
}

Parameters

bucketFactory

The bucket factory to use in RateLimiterFactory

limiterFactory

The RateLimiter factory in charge of handling buckets and rate limits

block

Further configures the RateLimitBuilder

See also