我正在为不和谐的服务器创建一个机器人,我需要知道它的工作时间和延迟。我正在使用命令处理程序来使命令更快。
我尝试了以下代码来创建正常运行时间命令。
const Discord = require('discord.js');
module.exports = {
name: 'uptime',
description: 'New command',
execute(client, message) {
let totalSeconds = (client.uptime / 1000);
const days = Math.floor(totalSeconds / 86400);
const hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
const choices = ['Checking servers...', 'Waking Dest up...', 'UHH. Okay, let me check...'];
const response = choices[Math.floor(Math.random() * choices.length)];
const exampleEmbed = new Discord.RichEmbed()
.setColor('#0099ff')
.attachFiles(['./assets/md.png'])
.setAuthor('Alpha Uptime.', 'attachment://md.png')
.addField('Days:', `${days}`)
.addField('Hours:', `${hours}`, true)
.addField('Minutes:', `${minutes}`, true)
.addField('Seconds:', `${seconds}`, true)
.setTimestamp()
.setFooter('by MadDest', 'attachment://md.png');
message.channel.send(`${response}`).then(m => {
const ping = m.ceatedTimestamp - message.createdTimestamp;
m.edit(`**[!]** Ping check and uptime updated! Bot Latency: ${ping}, API Latency: ${Math.round(client.Ping)}. ?`);
});
message.channel.send('**[!]** Uptime stats:');
message.channel.send(exampleEmbed);
},
};
但是它失败,并显示以下错误消息:
TypeError: Cannot read property 'send' of undefined
at Object.execute (C:\Users\Dest\Documents\AlphaBot\commands\uptime.js:28:19)
at Client.<anonymous> (C:\Users\Dest\Documents\AlphaBot\index.js:110:11)
at Client.emit (events.js:196:13)
at MessageCreateHandler.handle (C:\Users\Dest\Documents\AlphaBot\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\Dest\Documents\AlphaBot\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (C:\Users\Dest\Documents\AlphaBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (C:\Users\Dest\Documents\AlphaBot\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (C:\Users\Dest\Documents\AlphaBot\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:196:13)
at Receiver._receiver.onmessage (C:\Users\Dest\Documents\AlphaBot\node_modules\ws\lib\websocket.js:137:47)
是什么导致此操作失败,我该如何解决?