I was trying to make a ping command for my bot here is my Code
client.on('message', message => {
if (message.content === '+ping') {
message.channel.send(`🏓Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
}
});
However I end up getting the following error
C:\Users\ujjwa\Desktop\All Disc\Test all\index.js:236
message.channel.send(`🏓Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
^
ReferenceError: m is not defined
at Client.<anonymous> (C:\Users\lol\Desktop\All Disc\Test all\index.js:236:42)
at Client.emit (events.js:327:22)
at MessageCreateAction.handle (C:\Users\lol\Desktop\All Disc\Test all\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\lol\Desktop\All Disc\Test all\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\lol\Desktop\All Disc\Test all\node_modules\discord.js\src\client\websocket\WebSocketManager.js:386:31)
at WebSocketShard.onPacket (C:\Users\lol\Desktop\All Disc\Test all\node_modules\discord.js\src\client\websocket\WebSocketShard.js:436:22)
at WebSocketShard.onMessage (C:\Users\lol\Desktop\All Disc\Test all\node_modules\discord.js\src\client\websocket\WebSocketShard.js:293:10)
at WebSocket.onMessage (C:\Users\lol\Desktop\All Disc\Test all\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\lol\Desktop\All Disc\Test all\node_modules\ws\lib\websocket.js:797:20)
Can you help me out?
Press the “@” icon at the bottom of the screen. The “Recent Mentions” screen will display. To narrow down the pings you want to see, tap the “Filter Options” icon at the top-right corner. Under “Server Options,” select the appropriate option to see pings from the server you're on right now or “All Servers.”
There are also powerful APIs for creating Discord bots for those who prefer to take matters into their own hands. For instance, Discord. js allows us to create a simple Discord bot using Javascript.
You need to use Date.now() - message.createdTimestamp
to get the latency.
client.on('message', message => {
if (message.content === '+ping') {
message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
}
});
client.on('message', message => {
if (message.content === prefix + 'ping') {
message.channel.send('Loading data').then (async (msg) =>{
msg.delete()
message.channel.send(`🏓Latency is ${msg.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
})
}
});
I use this As My Ping Command (Sorry if I make Any Kind of Mistake, I just learned JavaScript in the last 2 Days)
module.exports={
name:'ping',
description: "Command ini digunakan untuk Ping",
execute(message, args){
message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms`);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With