Skip to content

Commit

Permalink
[New] Added uptime command to check when the bot was started
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Sep 16, 2021
1 parent fa54602 commit 99410a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions commands/misc/uptime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { embedMessage } = require("../../modules/embedSimple");
const { msToTime } = require("../../modules/mstoTime");

module.exports = {
data: new SlashCommandBuilder()
.setName("uptime")
.setDescription("Since how long the bot is online"),
async execute(interaction, client) {
await interaction.reply({
embeds: [
embedMessage(
"#9dcc37",
`${client.user.username}' Uptime: ${msToTime(client.uptime)}`
),
],
});
},
};
12 changes: 12 additions & 0 deletions modules/mstoTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports.msToTime = (duration) => {
let milliseconds = parseInt((duration % 1000) / 100),
seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);

hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

return hours + ":" + minutes + ":" + seconds + "." + milliseconds;
};

0 comments on commit 99410a7

Please sign in to comment.