I created a discord.js bot that works all the time. In the terminal where the bot is running I would like the running time of the bot since it started up to be displayed below "I am connected !".
Here is part of my console code :
client.on('ready', () => {
console.log('I am connected !');
Do you have any ideas ?
Thank you in advance for your help.
As suggested by @Lawrence Cherone, you can use a date in the top of the file to compare with one on ready. For example:
const startup = new Date()
// Other code...
client.on("ready" => {
const ready = new Date()
const diff = ready.getTime() - startup.getTime()
console.log(`I am connected! Startup took ${diff}ms`)
})
If you want the time in a format other than milliseconds, you can use ms, a tiny library written by Vercel devs on npm which converts milliseconds into human-friendly timestamps.