ping discord

how do i access discord api ping? code that i tried
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
let now = Date.now();
await interaction.reply('calculating...').then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${WebSocketManager.ping}`));
},
};
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
let now = Date.now();
await interaction.reply('calculating...').then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${WebSocketManager.ping}`));
},
};
No description
17 Replies
d.js toolkit
d.js toolkit3mo 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 staff
treble/luna
treble/luna3mo ago
<Client>.ws.ping
d.js docs
d.js docs3mo ago
Explaining <Class> and Class#method notation: learn more
treble/luna
treble/luna3mo ago
you dont call it on the class, its not a static property also its editReply, that should've errored right, reply returns an InteractionResponse , not an interaction
ggg,.
ggg,.OP3mo ago
okay bear my coding skills are low, but i'm still learning new code
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction,) {
let now = Date.now();
await interaction.reply(`${client.ws.ping}`)//.then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${Client.ws.ping}`));
},
};
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction,) {
let now = Date.now();
await interaction.reply(`${client.ws.ping}`)//.then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${Client.ws.ping}`));
},
};
new error
ReferenceError: client is not defined
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\commands\utility\ping.js:9:30)
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\events\interactions.js:16:18)
at Client.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\index.js:35:44)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:348:31)
at WebSocketManager.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:232:12)
at WebSocketManager.emit (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:287:31)
at WebSocketShard.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@discordjs\ws\dist\index.js:1190:51)
ReferenceError: client is not defined
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\commands\utility\ping.js:9:30)
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\events\interactions.js:16:18)
at Client.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\index.js:35:44)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:348:31)
at WebSocketManager.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:232:12)
at WebSocketManager.emit (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:287:31)
at WebSocketShard.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@discordjs\ws\dist\index.js:1190:51)
treble/luna
treble/luna3mo ago
you do need to define client yes that should be basic js virtually every djs structure has a client property
ggg,.
ggg,.OP3mo ago
ik this
treble/luna
treble/luna3mo ago
then use it
ggg,.
ggg,.OP3mo ago
should i refer to client in every command file?
treble/luna
treble/luna3mo ago
...no .
ggg,.
ggg,.OP3mo ago
then how do i set globely to every file?
treble/luna
treble/luna3mo ago
again virtually every djs structure has a client property so access it
ggg,.
ggg,.OP3mo ago
new error
TypeError: Cannot read properties of undefined (reading 'ping')
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\commands\utility\ping.js:9:40)
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\events\interactions.js:16:18)
at Client.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\index.js:35:44)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:348:31)
at WebSocketManager.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:232:12)
at WebSocketManager.emit (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:287:31)
at WebSocketShard.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@discordjs\ws\dist\index.js:1190:51)
TypeError: Cannot read properties of undefined (reading 'ping')
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\commands\utility\ping.js:9:40)
at Object.execute (C:\Users\SETUP GAME\Documents\project v6\VR community\events\interactions.js:16:18)
at Client.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\index.js:35:44)
at Client.emit (node:events:519:28)
at InteractionCreateAction.handle (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:348:31)
at WebSocketManager.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\discord.js\src\client\websocket\WebSocketManager.js:232:12)
at WebSocketManager.emit (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:287:31)
at WebSocketShard.<anonymous> (C:\Users\SETUP GAME\Documents\project v6\VR community\node_modules\@discordjs\ws\dist\index.js:1190:51)
treble/luna
treble/luna3mo ago
show your code
ggg,.
ggg,.OP3mo ago
ik im stupid but im learning
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction,) {
let now = Date.now();
await interaction.reply(`${Client.ws.ping}`)//.then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${Client.ws.ping}`));
},
};
const { Client, SlashCommandBuilder, WebSocketManager } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction,) {
let now = Date.now();
await interaction.reply(`${Client.ws.ping}`)//.then((interaction) => interaction.edit(`Pong : **${Date.now() - now}**ms\nDiscord API: ${Client.ws.ping}`));
},
};
treble/luna
treble/luna3mo ago
sigh this is basic js at this point i would advise you learn that first, then come back #rules 3 #resources
ggg,.
ggg,.OP3mo ago
okay sorry for my stupidity thanks for the help also my js skills are basic web front dev shit that's why i should probably familliars my self with node or wtv anyways sorry for bothering and thanks for the help
Want results from more Discord servers?
Add your server