eScord.js ping延迟从slash命令嵌入
新手在这里。我正在尝试获得一个斜杠命令,以发送嵌入,并在初始消息和消息响应时间之间花费的时间。我得到 typeError:无法读取未定义的属性(读取'CreateTimestamp')
和 error [Interaction_already_replied]:对此交互的答复已经发送或推迟
。我跳来跳去查看其他代码,试图找到一种方法来制作这项工作,但是Slash Command的处理对我来说仍然没有很多意义。我的代码块在下面。我跟随 https://discordjs.guide 因此,如果您有其他结构的建议,可以随意在下面发表评论。谢谢你!
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply("Pinging bot...").then (async (msg) =>{
const exampleEmbed = new MessageEmbed()
.setColor('0x0000ff')
.setTitle('Pong! :ping_pong:')
.addField("Time taken: ", `${msg.createdTimestamp - message.createdTimestamp}`)
.setThumbnail("https://78.media.tumblr.com/be43242341a7be9d50bb2ff8965abf61/tumblr_o1ximcnp1I1qf84u9o1_500.gif")
interaction.editReply({ embeds: [exampleEmbed] });
})
},
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要获取发送的答复,您可以使用获得互动答复。您可以推迟回复,然后使用CreateTimestamp,而不是使用“ Pinging Bot ...”回复。 ping命令的一个基本示例是,
您可以将响应自定义为嵌入或随心所欲。 DJ指南在ping命令在这里
first you need to fetch the reply you send, u can use fetchReply to get the interaction reply. instead of replying with "Pinging bot..." you can defer the reply and then use the createdTimestamp. A basic example of a ping command would be
You can customize the response into an embed or however you like. The djs guide has a section on ping command here