首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我正在尝试执行一个discord.js ping命令,但它显示以下错误

问我正在尝试执行一个discord.js ping命令,但它显示以下错误
EN

Stack Overflow用户
提问于 2021-10-21 05:08:39
回答 1查看 150关注 0票数 0

我正在尝试创建一个ping命令来显示延迟,但我遇到一个错误,我不知道它为什么会显示它,这就是错误-

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

代码语言:javascript
复制
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,请告诉我如何修复此错误,谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-10-21 16:23:18

将你的(消息,客户端)换成(客户端,消息)

代码语言:javascript
复制
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] });
},
};
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69656164

复制
相关文章

相似问题

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