discord.js v13 bot uptime

720 Views Asked by At

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}`)
    }
})
1

There are 1 best solutions below

0
MrMythical On BEST ANSWER

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}`)
    }
})