首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我试图创建一个显示ms的!ping命令,但是我得到了这个错误

问我试图创建一个显示ms的!ping命令,但是我得到了这个错误
EN

Stack Overflow用户
提问于 2021-08-17 20:40:49
回答 1查看 21关注 0票数 0

当我运行它时,机器人会按照我添加的命令正常运行,但当我这样做的时候!在聊天中ping它会在终端中给我一个错误

这是我的代码

代码语言:javascript
复制
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.`);
    },
});

这就是错误

代码语言:javascript
复制
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“

EN

回答 1

Stack Overflow用户

发布于 2021-08-17 21:06:52

在您的ping命令中尝试此命令,我正在尝试与您刚才所做的相同的事情,所以我尝试了此命令,它起作用了

const {客户端}= require("discord.js");

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

module.exports =新命令({ name:" ping ",description:“显示机器人的ping!”,

代码语言:javascript
复制
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]})
      });
},

});

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68823778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档