create Default
fun createDefault(scope: RateLimitScope, configurationSupplier: BucketConfigurationSupplier, deleteOnRefill: Boolean = true): RateLimiter(source)
Creates a default RateLimiter implementation, see DefaultRateLimitHandler and InMemoryBucketAccessor for details.
Example
@Command
class SlashInMemoryRateLimit : ApplicationCommand(), GlobalApplicationCommandProvider {
fun onSlashInMemoryRateLimit(event: GuildSlashEvent) {
event.reply_("Hi", ephemeral = true).queue()
}
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) {
manager.slashCommand("in_memory_rate_limit", function = ::onSlashInMemoryRateLimit) {
// Allow using the command once every 10 seconds
// NOTE: this won't take effect if you are the bot owner
val cooldown = Buckets.ofCooldown(10.seconds)
// Apply limit on each user, regardless or guild/channel
val rateLimiter = RateLimiter.createDefault(RateLimitScope.USER, cooldown.toSupplier())
// Register anonymous rate limit, only on this command
rateLimit(rateLimiter)
}
}
}
Content copied to clipboard
Parameters
scope
Scope of the rate limit, see RateLimitScope values.
configuration Supplier
A supplier of BucketConfiguration, describing the rate limits
delete On Refill
Whether the rate limit message should be deleted after expiring