Discord.js Ping 命令
2020-08-14
100672
我试图为我的机器人创建一个 ping 命令,这是我的代码
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`);
}
});
但是我最终收到以下错误
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)
你能帮帮我吗?
3个回答
您需要使用
Date.now() - message.createdTimestamp
来获取延迟。
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`);
}
});
Static
2020-08-14
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`);
})
}
});
PeterGamez
2020-11-09
我使用这个作为我的 Ping 命令(如果我犯了任何错误请见谅,我刚刚在过去的两天里学习了 JavaScript)
module.exports={
name:'ping',
description: "Command ini digunakan untuk Ping",
execute(message, args){
message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms`);
}
};
Fachri
2021-01-03