I had a question, so I know to add a timestamp to a New Discord.MessageEmbed()
you would use .setTimestamp()
, however, I was wondering how I would go about adding x amount of time to that timestamp, i.e. if my args[1] was "12hr" (12 hours), how would I make the timestamp display a time 12 hours ahead of whoever is viewing the message?
Basically, I'm creating a giveaway-type bot, for personal use, and I'd like the footer to display the end date.
Discord Node.js
Let's say you have let timeAdded = 12h;
. There is ms
package for translating that to time in milliseconds.
Also, note that .setTimestamp()
method has optional parameter timestamp
, that defaults to Date.now()
.
If you connect all this information, you'll get:
const ms = require('ms');
let timeAdded = '12h';
const NewEmbed = new Discord.MessageEmbed()
.setTimestamp(Date.now() + ms(timeAdded));
And that's it! Of course timeAdded
will have to come from your args
string, or in some way be fetched from the message, but you get the idea.