discordx-ts / discordx

🤖 Create a discord bot with TypeScript and Decorators!
https://discordx.js.org
Apache License 2.0
607 stars 50 forks source link

[Feature]: Add Rate Limit to buttons #866

Closed B0tis closed 1 year ago

B0tis commented 1 year ago

Feature?

Hi, currently it is possible to Rate Limit the usage of commands but not from Button Interactions.

It would be nice that this Feature would be added if possible :)

Package

@discordx/utilities

TeamWolfyta commented 1 year ago

Are you wanting to know if there is a way to rate limit buttons or commands ?

B0tis commented 1 year ago

For Buttons, it would be nice to know, for Commands it's already possible

TeamWolfyta commented 1 year ago

I know something for commands already exists, It's just the way you phrased your message was a bit all over the place.

Why would you need a rate limit for buttons ? In some way discord makes you wait a bit before each button press anyways.

B0tis commented 1 year ago

Well, I would like to have the possibility that the User can only use the Button once every Minute...

TeamWolfyta commented 1 year ago

Have you tried using RateLimit on a button since if I remember correctly button has a interaction parameter which is what RateLimit uses ?

edit: I'm going to give it a try now.

TeamWolfyta commented 1 year ago

Yup, RateLimit works on buttons.

B0tis commented 1 year ago

could you send me a Screenshot how you did that, i just get an error lol

TeamWolfyta commented 1 year ago

I already deleted the temp project I did it in but all's I did was:

@ButtonComponent({ id: "hello-btn" })
@Guard(
    RateLimit(TIME_UNIT.seconds, 30, {
        message: "Please wait `30` seconds!",
    })
)
helloBtn(interaction: ButtonInteraction): void {
    interaction.reply(`👋 ${interaction.member}`);
}
B0tis commented 1 year ago

ahhh lol, thx forgot the @Guards xD