我正在尝试创建一个命令,当输入/ping命令时,它返回一个嵌入的消息,我得到这个错误。
.setColor("#FF0000")
^
TypeError: (intermediate value).setColor is not a function
at Object.run (C:UsersdhartDesktopProjectsExistentialThreatcommandsInfoping.js:9:8)
at Client.<anonymous> (C:UsersdhartDesktopProjectsExistentialThreateventsinteractionCreate.js:24:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
我的代码是:
const { Embed } = require("discord.js");
module.exports = {
name: "ping",
description: "Returns websocket latency",
run: async (client, interaction) => {
const embed = new Embed()
.setColor("#FF0000")
.setTitle("🏓 Pong!")
.setDescription(`Latency : ${client.ws.ping}ms`)
.setTimestamp()
.setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
interaction.followUp({ embeds: [embed] });
},
};
我不知道如何解决这个问题,我希望得到一些帮助。
在discord.js v14中,MessageEmbed
已被重命名为EmbedBuilder
。当您尝试导入和使用Embed
类时,您会收到该错误。
您将需要EmbedBuilder
代替:
const { EmbedBuilder } = require('discord.js');
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("🏓 Pong!")
.setDescription(`Latency : ${client.ws.ping}ms`)
.setTimestamp()
.setFooter({
text: `Requested by ${interaction.user.tag}`,
iconURL: `${interaction.user.displayAvatarURL()}`,
});
interaction.followUp({ embeds: [embed] });