Use BucketBuilder to define how commands are rate limited within the StandardFramework. You can specify the scope of the limit (Global, User, Guild, Channel, or Category), the delay between invocations, the number of allowed invocations within a specific time span, and custom actions when a limit is exceeded.
Key Configuration Methods:
new_global(), new_user(), new_guild(), new_channel(), new_category(): Sets the scope of the rate limit.delay(secs: u64): Sets the minimum duration between command invocations.time_span(secs: u64): Sets the window of time for the limit to apply.limit(n: u32): Sets the maximum number of allowed invocations within the time_span.await_ratelimits(amount: u32): If greater than 0, the command invocation will be delayed amount times instead of being cancelled. This is required to trigger delay_action.delay_action(action: DelayHook): Provides a callback function to execute when a user's command is delayed (e.g., sending a custom warning message). This automatically sets await_ratelimits to at least 1.check(check: Check): Adds a middleware function to verify if the command invocation is eligible for the bucket.
let framework = StandardFramework::new()
.bucket("example_bucket", BucketBuilder::default()
.delay_action(|ctx, msg| {
Box::pin(example_overuse_response(ctx, msg))
})
.delay(10) // 10 second delay
.await_ratelimits(1) // Allow 1 delay action to trigger
)
.await
.group(&GENERAL_GROUP);