I am trying to create a command where it returns an embedded message when /ping command is typed and I am getting this error.
.setColor("#FF0000")
^
TypeError: (intermediate value).setColor is not a function
at Object.run (C:\Users\dhart\Desktop\Projects\ExistentialThreat\commands\Info\ping.js:9:8)
at Client.<anonymous> (C:\Users\dhart\Desktop\Projects\ExistentialThreat\events\interactionCreate.js:24:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
My code is:
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] });
},
};
Idk how to fix this and I would appreciate some help.
In discord.js v14 MessageEmbed
has been renamed to EmbedBuilder
. As you're trying to import and use the Embed
class, you receive that error.
You'll need to require EmbedBuilder
instead:
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] });