Ping Bot

Guys, I can't seem to get the correct values, for example Discord API value is not good at all, it is displayed at -1ms, how can I fix this?
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Get latency'),
async execute(interaction) {
const StartTime = Date.now();

await interaction.reply("Établissement de la connexion en cours...").then(async msg => {
const endTime = Date.now();
const websocketPing = interaction.client.ws.ping;

const pingEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Latence du bot')
.setDescription('La latence du bot est définie par un point de terminaison entre l\'API Discord et le client. Cette valeur peut ne pas être stable en fonction du trafic et des requêtes :computer:')
.addFields(
{ name: 'Latence du bot', value: `${endTime - StartTime}ms`, inline: true },
{ name: 'Latence de l\'API Discord', value: `${websocketPing}ms`, inline: true },
{ name: 'Node', value: 'api.maybe-ange.com', inline: true }
);

await interaction.editReply({ content: " ", embeds: [pingEmbed] });
console.log(`Commande /ping exécutée par ${interaction.user.tag} dans ${interaction.channel.name} (${interaction.guild.name})`);
});
},
};
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Get latency'),
async execute(interaction) {
const StartTime = Date.now();

await interaction.reply("Établissement de la connexion en cours...").then(async msg => {
const endTime = Date.now();
const websocketPing = interaction.client.ws.ping;

const pingEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Latence du bot')
.setDescription('La latence du bot est définie par un point de terminaison entre l\'API Discord et le client. Cette valeur peut ne pas être stable en fonction du trafic et des requêtes :computer:')
.addFields(
{ name: 'Latence du bot', value: `${endTime - StartTime}ms`, inline: true },
{ name: 'Latence de l\'API Discord', value: `${websocketPing}ms`, inline: true },
{ name: 'Node', value: 'api.maybe-ange.com', inline: true }
);

await interaction.editReply({ content: " ", embeds: [pingEmbed] });
console.log(`Commande /ping exécutée par ${interaction.user.tag} dans ${interaction.channel.name} (${interaction.guild.name})`);
});
},
};
3 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck10mo ago
<Client>.ws.ping is for heartbeat latency -1 is just the default value before the first heartbeat, so it sounds like you just haven't waited long enough for the first heartbeat to have been sent
Maybe Ange
Maybe AngeOP10mo ago
Thx Hum, dude, i've problem In this code, the bot gets stuck on the phrase that you probably won't understand since it's French, but it gets stuck on the phrase "await interaction.reply", how can I patch that? The bot works from time to time when I restart, we would say approximately that it works one time in 5 https://starb.in/qxsArp.js Mhm, I see
Want results from more Discord servers?
Add your server