I have created a bot js command which every 5 seconds updates status on website whether it’s online or not. Timestamp as well displays current time, but for some reason after some time it starts to get delayed by minute by two and then last you know it’s delayed by hours. I think it’s has something to do with those 5 seconds of status check.
const tcpp = require('tcp-ping');
const { EmbedBuilder } = require('discord.js');
let statusMessage = null;
module.exports = {
checkWeb: async (client) => {
try {
const website = {
name: "mysite",
url: "mysite.com",
port: 80
};
tcpp.probe(website.url, website.port, function(err, available) {
if (err) {
throw new Error(`Error probing website: ${err}`);
}
const status = available ? "???? Online" : "???? Offline";
const color = available ? "#00FF00" : "#FF0000";
const description = available ? `The ${website.url} is up and running.` : `The ${website.url} is offline.`;
const embed = new EmbedBuilder()
.setTitle(`Status of ${website.name}`)
.setDescription(`${description}nnStatus: ${status}nu200B`)
.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.setTimestamp()
.setColor(color);
if (!statusMessage) {
client.channels.cache.get('1232582546932633610').send({ embeds: })
.then(message => {
statusMessage = message.id;
});
} else {
client.channels.cache.get('1232582546932633610').messages.fetch(statusMessage)
.then(message => {
message.edit({ embeds: });
})
.catch(console.error);
}
});
} catch (error) {
console.error(`Error checking website status: ${error}`);
} finally {
setTimeout(() => module.exports.checkWeb(client), 5 * 1000);
}
}
};