Comments (3)
expiredTimestamp
is defined based on expirationTime
, which adds the cooldownAmount
to the timestamp of the last use:
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmount;
// ...
const expiredTimestamp = Math.round(expirationTime / 1000);
from guide.
I know, this is the code that I have, what I wanted to say, is that in discord the time of the message that shows <t: :R>
shows a timestamp from when the message was started, but the text implies that it should show a countdown of how much time is left to use the message, am I right or what the guide shows is wrong?
Continue to count the time elapsed, example of the bot response using the example in the guide:
Please wait, you are on a cooldown for ping. You can use it again in 16 seconds ago
My code:
const { Collection, Interaction } = require('discord.js')
module.exports =
{
/**
* Checks if the user is in timeout to re-execute a certain command, if yes it returns true, otherwise it returns false.
* @param { Interaction } interaction
* @param { object } command
* @returns { Boolean }
*/
hasCooldown: async (interaction, command) =>
{
if(!command.cooldown) return false
const { cooldowns } = interaction.client
if (!cooldowns.has(command.data.name)) cooldowns.set(command.data.name, new Collection())
const now = Date.now()
const timestamps = cooldowns.get(command.data.name)
const cooldownAmmount = command.cooldown * 1000
if (timestamps.has(interaction.user.id))
{
const expirationTime = timestamps.get(interaction.user.id) + cooldownAmmount
if (now < expirationTime)
{
const expiredTimestamp = Math.round(expirationTime / 1000)
return !!interaction.reply({ content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again in <t:${expiredTimestamp}:R>.`, ephemeral: true })
}
}
timestamps.set(interaction.user.id, now)
setTimeout(() => timestamps.delete(interaction.user.id), cooldownAmmount)
return false
}
}
from guide.
It seems to me that the only solution is that once the countdown reaches 0, before the counter starts to increase its value, delete the interaction.
if (now < expirationTime)
{
const expiredTimestamp = Math.round(expirationTime / 1000)
interaction.reply({ content: `Please wait, you are on a cooldown for \`${command.data.name}\`. You can use it again in <t:${expiredTimestamp}:R>`, ephemeral: true })
setTimeout(() => { interaction.deleteReply() }, expirationTime - now)
return true
}
from guide.
Related Issues (20)
- Incorrect documentation, Modals on Guide.
- guide-event-handling-interactionCreate.js HOT 5
- Duplicate file HOT 3
- Edit Cooldowns page in event that an Event handler was made. HOT 4
- v14 Deploy Commands code not working
- Unclear documentation - what does 'target' mean HOT 2
- Let's comfortably reach more communities HOT 3
- Use glob instead of fs HOT 2
- Reloading Commands has a code snippet that doesn't match the explanation
- Question
- Can bot send voice (aka audio) messages as users can send in mobile app?
- tutorial ES6 update HOT 3
- Timeouts HOT 1
- Sequential Steps HOT 3
- Option Support For Modals HOT 1
- Setting up a linter isn't work since ^9.0.0 HOT 1
- Cannot find module "node_modules\@discordjs\voice\dist\index.js" HOT 2
- Update information about blank fields in embed guide HOT 7
- Can the guide be updated with information about GuildScheduledEvents and Polls
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guide.