How get bot latency?

bot.ws.ping return -1 bot.ping return NaN Date.now() - message.createdTimestamp not is latency
8 Replies
d.js toolkit
d.js toolkit13mo 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! - Marked as resolved by OP
vo0ov
vo0ovOP13mo ago
discord.js - 14.13.0 Node.js - v21.1.0
treble/luna
treble/luna13mo ago
Ping returns -1 initially because the first heartbeat hasn't been sent yet That can take max 41s
vo0ov
vo0ovOP13mo ago
The ping is sometimes real, but most often it is -1.
const { Events } = require('discord.js');

function command(bot) {
bot.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'ping') {
await interaction.reply({embeds: [{title: 'Измерение пинга', description: `Мой пинг ${Math.round(bot.ws.ping)}мс.`, color: 0x00ff00, thumbnail: {url: bot.user.displayAvatarURL()}}]});
};
});
}

module.exports = command;
const { Events } = require('discord.js');

function command(bot) {
bot.on(Events.InteractionCreate, async (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'ping') {
await interaction.reply({embeds: [{title: 'Измерение пинга', description: `Мой пинг ${Math.round(bot.ws.ping)}мс.`, color: 0x00ff00, thumbnail: {url: bot.user.displayAvatarURL()}}]});
};
});
}

module.exports = command;
No description
No description
vo0ov
vo0ovOP13mo ago
@wolvinny 🌈
probablyraging
probablyraging13mo ago
Wait for the bot to send its first heartbeat, which is usually 41ms after the WS connected
treble/luna
treble/luna13mo ago
41s
vo0ov
vo0ovOP13mo ago
I'm waiting more than 41ms after starting the bot. Or need 41 seconds?
Want results from more Discord servers?
Add your server