尝试制作一个显示ms的!ping命令,但我得到这个错误



当我运行它时,bot按照我添加的命令运行,但是当我在聊天中执行!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:UsersAlyDesktopSpidBotsrcCommandsping.js:9:36)
at Client.<anonymous> (C:UsersAlyDesktopSpidBotsrcindex.js:42:10)
at Client.emit (node:events:394:28)
at MessageCreateAction.handle (C:UsersAlyDesktopSpidBotnode_modulesdiscord.jssrcclientactionsMessageCreate.js:23:14)
at Object.module.exports [as MESSAGE_CREATE] (C:UsersAlyDesktopSpidBotnode_modulesdiscord.jssrcclientwebsockethandlersMESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:UsersAlyDesktopSpidBotnode_modulesdiscord.jssrcclientwebsocketWebSocketManager.js:345:31)
at WebSocketShard.onPacket (C:UsersAlyDesktopSpidBotnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:443:22)
at WebSocketShard.onMessage (C:UsersAlyDesktopSpidBotnode_modulesdiscord.jssrcclientwebsocketWebSocketShard.js:300:10)
at WebSocket.onMessage (C:UsersAlyDesktopSpidBotnode_moduleswslibevent-target.js:132:16)

我真的不知道我应该做什么,当我删除"。was "(在第9行)命令工作,但它告诉我&;undefined ms"在聊天

尝试这个ping命令,我正在尝试同样的事情,所以我尝试了这个,它工作

const {Client} = require("discord.js");

const Command = require("…/Structures/Command.js");

模块。exports = new Command({名称:"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]})
});
},

});

相关内容

  • 没有找到相关文章

最新更新