Search code examples
node.jsdiscorddiscord.jstimestamp

Discord.js v14 Add 12h on a timestamp


I know how to put a timestamp in a Discord embed. Except that I can't put the timestamp +12h.

I tried this

const ms = require('ms');
let timeAdded = '12h';
const embed = new EmbedBuilder()
                    .setTimestamp()
                    .setColor('3564fa')
                    .setFooter({ text: `💗 Merci de soutenir le projet ${interaction.user.tag}`, iconURL: client.user.avatarURL()})
                    .setDescription(`Vous pouvez votez pour ${client.user} en votant **[ici](https://top.gg/fr/bot/931808039231713301/vote 'GrayBot vote')**. Vous pourrez revoter dans <t:${Math.floor(new Date().getTime() + ms(timeAdded)/ 1000)}:R>`)
                    
                return interaction.reply({ embeds: [embed]})

This returns me a date in which is 5000 years...


Solution

  • You're only dividing the amount you're adding by 1000. You need to divide the whole thing by 1000. Math.floor((new Date().getTime() + ms(timeAdded)) / 1000) (note the extra parenthesis)