【问题标题】:I am trying to make a discord.js ping command with latency but it shows this error我正在尝试使用延迟的 discord.js ping 命令,但它显示此错误
【发布时间】:2021-12-07 21:00:44
【问题描述】:

我正在尝试制作一个显示延迟的 ping 命令,但我遇到了一个错误,我不知道它为什么会显示它,这是错误 -

TypeError: Cannot read properties of undefined (reading 'ping')
    at Object.execute (C:\Users\Ayush Kumar\Desktop\AniVenture\commands\utility\ping.js:10:74)
    at Client.<anonymous> (C:\Users\Ayush Kumar\Desktop\AniVenture\index.js:78:11)
    at Client.emit (node:events:390:28)
    at MessageCreateAction.handle (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\discord.js\src\client\actions\MessageCreate.js:23:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
    at WebSocketManager.handlePacket (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\discord.js\src\client\websocket\WebSocketManager.js:350:31)
    at WebSocketShard.onPacket (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\discord.js\src\client\websocket\WebSocketShard.js:443:22)
    at WebSocketShard.onMessage (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\discord.js\src\client\websocket\WebSocketShard.js:300:10)
    at WebSocket.onMessage (C:\Users\Ayush Kumar\Desktop\AniVenture\node_modules\ws\lib\event-target.js:199:18)      
    at WebSocket.emit (node:events:390:28)

ping.js 中的代码 -

const Discord = require("discord.js");

module.exports = {
name: 'ping',  
cooldown: 4,
execute(message, client) {
    const bot = message.createdTimestamp - Date.now();
    const ping = new Discord.MessageEmbed()
    .setTitle("Pong! :ping_pong:")
    .setDescription(`Bot latency: \`${bot}ms\`\n API latency: \`${client.ws.ping}ms\``)
    .setColor("#31e8b7")
    .setTimestamp()
    .setFooter(`${message.author.tag}`);
    message.channel.send({ embeds: [ping] });
},
};

我正在使用 discord.js v13,请告诉我如何解决此错误, 谢谢。

【问题讨论】:

  • 你定义client了吗?
  • 是的@Jim,我做到了
  • 请帮助某人

标签: javascript node.js discord.js


【解决方案1】:

用(客户端,消息)交换您的(消息,客户端)

execute(client, message) {
    const bot = message.createdTimestamp - Date.now();
    const ping = new Discord.MessageEmbed()
    .setTitle("Pong! :ping_pong:")
    .setDescription(`Bot latency: \`${bot}ms\`\n API latency: \`${client.ws.ping}ms\``)
    .setColor("#31e8b7")
    .setTimestamp()
    .setFooter(`${message.author.tag}`);
    message.channel.send({ embeds: [ping] });
},
};

【讨论】:

  • 嘿,谢谢,但它仍然显示相同的错误
  • arburich 你能帮忙吗?
猜你喜欢
  • 1970-01-01
  • 2018-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-28
  • 2021-08-25
  • 1970-01-01
  • 2020-01-28
相关资源
最近更新 更多