当我运行它时,机器人会按照我添加的命令正常运行,但当我这样做的时候!在聊天中ping它会在终端中给我一个错误
这是我的代码
const { Client } = require("discord.js");
const Command = require("../Structures/Command.js");
module.exports = new Command({
name: "ping",
description: "Shows the ping of the bot!",
async run(message, args, client) {
message.reply(`Ping: ${Client.ws.ping} ms.`);
},
});这就是错误
TypeError: Cannot read property 'ping' of undefined
at Command.run (C:\Users\Aly\Desktop\SpidBot\src\Commands\ping.js:9:36)
at Client.<anonymous> (C:\Users\Aly\Desktop\SpidBot\src\index.js:42:10)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:\Users\Aly\Desktop\SpidBot\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Aly\Desktop\SpidBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Users\Aly\Desktop\SpidBot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:345:31)
at WebSocketShard.onPacket (C:\Users\Aly\Desktop\SpidBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:\Users\Aly\Desktop\SpidBot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
at WebSocket.onMessage (C:\Users\Aly\Desktop\SpidBot\node_modules\ws\lib\event-target.js:132:16)我真的不知道我应该做什么,当我删除".ws“(在第9行)时,命令可以工作,但它在聊天中告诉我”未定义的ms“
发布于 2021-08-17 21:06:52
在您的ping命令中尝试此命令,我正在尝试与您刚才所做的相同的事情,所以我尝试了此命令,它起作用了
const {客户端}= require("discord.js");
const Command = require("../Structures/Command.js");
module.exports =新命令({ name:" ping ",description:“显示机器人的ping!”,
async run(message, args, client) {
message.channel.send("Pinging...").then(m =>{
let ping = m.createdTimestamp - message.createdTimestamp;
// Basic embed
let embed = new MessageEmbed()
.setAuthor(`Your ping is ${ping}`)
.setColor("RANDOM")
// Then It Edits the message with the ping variable embed that you created
m.edit({ embeds: [embed]})
});
},});
https://stackoverflow.com/questions/68823778
复制相似问题