button cooldown

how would i make a cooldown on a button? I found something on google, but it looks like it's a cooldown for all buttons, i just want a cooldown for a specific button (it should not be a global cooldown, but just a cooldown per user)
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MoonlightCapital
what did you find? i think you can adapt it to your needs
Tissemyren
TissemyrenOP2y ago
found this
// At the top of your file
const buttonCooldown = new Set()

client.on("interactionCreate", (ctx) => {
if(!ctx.isButton()) return;
if(buttonCooldown.has(ctx.user.id)) {
// user is on cooldown, do whatever you want
}
buttonCooldown.add(ctx.user.id)
setTimeout(() => buttonCooldown.delete(ctx.user.id), 10_000) // replace 10_000 with cooldown time
// other logic here
})
// At the top of your file
const buttonCooldown = new Set()

client.on("interactionCreate", (ctx) => {
if(!ctx.isButton()) return;
if(buttonCooldown.has(ctx.user.id)) {
// user is on cooldown, do whatever you want
}
buttonCooldown.add(ctx.user.id)
setTimeout(() => buttonCooldown.delete(ctx.user.id), 10_000) // replace 10_000 with cooldown time
// other logic here
})
MoonlightCapital
i'd use a map/collection instead of a set so you can also store the button custom id (or concatenate them into a string and put them in the set)
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server