0

I made some bot uptime code but got an error showing 52 years ago The code is below.

const style = 'R'
const starttime = `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'

client.on('messageCreate' , message=>{
    if(message.content == "!uptime"){
        message.reply(`uptime!\n uptime : ${starttime}`)
    }
})
MrMythical
  • 8,908
  • 2
  • 17
  • 45
  • Does this answer your question? [Get Uptime of Discord.JS bot](https://stackoverflow.com/questions/49912703/get-uptime-of-discord-js-bot) – Gaurish Feb 09 '22 at 22:07

1 Answers1

0

You are setting that outside of the event, where client.readyAt is null. When you divide null by anything except for 0, you get 0. The result would then be <t:0:R>. You could either make this a function, or set it in the event

function generateReadyTimestamp() {
  return `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'
}
// ...
message.reply(`uptime!\n uptime : ${generateReadyTimestamp()}`)

Or, setting it inside the callback:

client.on('messageCreate', message => {
    if(message.content == "!uptime"){
        const starttime = `<t:${Math.floor(client.readyAt / 1000)}` + (style ? `:${style}` : '') + '>'
        message.reply(`uptime!\n uptime : ${starttime}`)
    }
})
MrMythical
  • 8,908
  • 2
  • 17
  • 45