for several days I’ve been trying to make a time difference but I can’t, to better explain to you:
I made 2 .js files, one file to take a service and it gives a role to say that the person took his service and the other file to make an end of service and it removes the role by putting in an embed the precise date, hours, minutes and seconds, just like for the service take, I managed to do that but the problem is that I would like the bot to subtract my 2 hours (the one from taking service and end of service to have the total number of hours he did during his service) but I can’t do it, if someone has an idea I’m interested !
const { Client, ApplicationCommandOptionType, PermissionFlagsBits, InteractionResponse, EmbedBuilder } = require("discord.js");
config = require('../config.json');
module.exports = {
name: "start",
description: `start serving `,
run: async (client, interaction, message) => {
var dt = new Date(Date.now())
var now = dt.toLocaleDateString('en-En')
var hours = (dt.getHours() < 10?"0":"") + dt.getHours()
var minutes = (dt.getMinutes() < 10?"0":"") + dt.getMinutes()
var seconds = (dt.getSeconds() < 10?"0":"") + dt.getSeconds()
var day = (dt.getDate() < 10?"0":"") + dt.getDate()
var month = (dt.getMonth()+1 < 10?"0":"") + (dt.getMonth()+1)
var year = dt.getFullYear()
var all = day + "/" + month + "/" + year + " • " + hours + ":" + minutes + ":" + seconds
const service_plug = new EmbedBuilder()
.setColor("Green")
.setDescription(`**${interaction.member.user}** took his service !`)
.setFooter({ text: all });
await interaction.deferReply({ ephemeral: true });
if (interaction.member.roles.cache.has("1067700186274603008")) return interaction.followUp({ content: `:x: You are already in service` });
if (!interaction.guild.members.me.permissions.has(PermissionFlagsBits.Administrator)) return interaction.followUp({ content: `:x: I don't have the required permission for this command to work !` });
interaction.member.roles.add(config.role_start)
interaction.followUp({ content: `You took your service !`})
interaction.guild.channels.cache.get(config.logs_start).send({ embeds: [ service_plug ] }).catch(() => {})
}
}
Here is the code of the command to start its service, that of the end of service is exactly the same except that it removes the role of the member