Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Looking for uptime command
const { Client, Message, MessageEmbed, Permissions } = require("discord.js");
const emojis = require("../../config/emojis.json");
const db = require("quick.db");
const { player } = require("../index");
const embed = require("../structures/embeds");

module.exports = {
  name: "ping",
  aliases: [],
  description: "test",

  /**
   *
   * @param {Client} client
   * @param {Message} message
   * @param {Guild} guild
   */
  run: async (client, message, args, prefix, lang) => {
    try {
      message.reply({
        content: "Ping: " + client.ws.ping + "ms 📶",
      });
    } catch {
      console.log("rexom");
    }
  },
};

this is how i got my ping command, i am looking for a uptime command can someone help?
so i tested many examples it isn't working into my project, i am looking for someone provides me or gives me the code connected to the way how ping code is made because that will make the command to work :)

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use Node's built-in process.uptime() function for this:


module.exports = {
  name: "uptime",
  aliases: [],
  description: "Returns the bot's uptime in milliseconds",

  /**
   *
   * @param {Client} client
   * @param {Message} message
   * @param {Guild} guild
   */
  run: async (client, message, args, prefix, lang) => {
    try {
      // multiply process.uptime() return value by 1000, and round it 
      // to a whole number to get ms.
      message.reply({
        content: "Uptime: " + Math.round(process.uptime() * 1000) + "ms 📶",
      });
    } catch {
      console.log("rexom");
    }
  },
};

Edit (03/16/2021)

Since you asked in the comments for code that responds with a days/hours/minutes/seconds string as uptime instead of just the number of milliseconds like your code implied, here is how you would do that, though, in the future you should be more clear with your question:


function uptimeString(seconds) {
    let days = Math.floor(seconds / (3600*24));
    seconds -= days*3600*24;
    let hours = Math.floor(seconds / 3600);
    seconds -= hours*3600;
    let minutes = Math.floor(seconds / 60);
    seconds -= minutes*60;
    return `${days} Days, ${hours} Hours, ${minutes} Minutes, and ${seconds} seconds`;
}


module.exports = {
  name: "uptime",
  aliases: [],
  description: "Returns the bot's uptime in milliseconds",

  /**
   *
   * @param {Client} client
   * @param {Message} message
   * @param {Guild} guild
   */
  run: async (client, message, args, prefix, lang) => {
    try {
      // call the function defined above with process.uptime() as the 
      // parameter. Floor the parameter to round down.
      message.reply({
        content: uptimeString(Math.floor(process.uptime())),
      });
    } catch {
      console.log("rexom");
    }
  },
};

This is what the response looks like in Discord:

Discord uptime command response

My bot uses slash commands, but the code I provided will work with message.reply().

about 4 years ago · Juan Pablo Isaza Report

0

You can use client.uptime to do so. It returns how long it has been since the client last entered the READY state in milliseconds. See the code below to see how this works:

const days = Math.floor(client.uptime / 86400000);
const hours = Math.floor(client.uptime / 3600000) % 24;
const minutes = Math.floor(client.uptime / 60000) % 60;
const seconds = Math.floor(client.uptime / 1000) % 60;
const uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;

console.log(`The bot has been up for ${uptime}`);

The code above makes it into a human-readable format.

Hoped this helped!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!