[Feature]: Option to Separate Rate Limiting for CommandInteraction and AutocompleteInteraction
testsnake opened this issue · comments
Feature?
I've encountered an issue where using SlashOption
's autocomplete triggers the RateLimit
guard every time the query is updated, meaning it is practically impossible to use the command unless a user waits out the cooldown between entering the query and sending the command.
Would love if there was an option to rate limit CommandInteraction
and AutocompleteInteraction
separately, or even just outright ignoring AutocompleteInteraction
all together.
Package
@discordx/utilities
@testsnake could you please provide a test code? I am confused, guards were not supposed to execute when using autocomplete. I would like to understand what went wrong.
This is the code I was having issues with
@Discord()
@Guard(RateLimit(TIME_UNIT.seconds, 30, {
ephemeral: true,
message: rateLimitMessage,
}))
export class Example {
@Slash({
name: "example",
})
private async Example(
@SlashOption({
autocomplete: true,
required: true,
type: ApplicationCommandOptionType.String
}) searchText: string,
interaction: CommandInteraction | AutocompleteInteraction
): Promise<void> {
if (interaction.isAutocomplete()) {
// Autocomplete Handler
} else {
// Command Handler
}
}
}
I realized this morning that it's probably not an issue when putting an arrow function as the autocomplete value instead of true, however the docs don't show how to get the user input with that method and I can't seem to figure it out myself.
@testsnake you can access through interaction.options
. for ex. const focusedValue = interaction.options.getFocused();
And yeah, I would recommend use autocomplete resolver.
However if you still want to use RateLimiter like your example. I say, make a wrapper like @Guard(SkipAutocomplete(RateLimit())
.
Alright yeah, that works. Thanks for your help! Not sure if this issue should be closed or not.
@testsnake Currently, I am bringing this to a close. A potential solution exists, and if there is repeated demand for it, we may consider implementing it. Appreciate your effort in keeping us informed.