Home > Net >  Discord.js error when trying to create and send an embed
Discord.js error when trying to create and send an embed

Time:10-03

I'm creating a Discord bot using Discord.js and Node.js, but when trying to make an embed I get this error:

TypeError: (intermediate value).setTitle(...).setColor(...).addField is not a function

I have not made a Discord bot before and am also using this as a way to learn JavaScript so this could be a stupid question, but thanks for your help!

edit: I should probably include the full code

client.on('messageUpdate', (oldMessage, newMessage) => {
const EditEmbed = new EmbedBuilder()
.setTitle("EDITED MESSAGE")
.setColor("#fc3c3c")
.addField("Author", oldMessage.author.tag, true)
.addField("Edited By", newMessage.author.tag, true)
.addField("Channel", oldMessage.channel, true)
.addField("Old Message", oldMessage.content || "None")
.addField("New Message", newMessage.content || "None")
.setFooter(`Message ID: ${oldMessage.id} | Author ID: ${oldMessage.author.id}`);

  const EditChannel = messageUpdate.guild.channels.find(x => x.name === "audit");
  EditChannel.send(EditEmbed);
 });

CodePudding user response:

You seem to be calling class methods wrongly, do this instead

client.on('messageUpdate', (oldMessage, newMessage) => {

    const EditEmbed = new EmbedBuilder();

    EditEmbed.setTitle("EDITED MESSAGE");
    EditEmbed.setColor("#fc3c3c");
    EditEmbed.addField("Author", oldMessage.author.tag, true);
    EditEmbed.addField("Edited By", newMessage.author.tag, true);
    EditEmbed.addField("Channel", oldMessage.channel, true);
    EditEmbed.addField("Old Message", oldMessage.content || "None");
    EditEmbed.addField("New Message", newMessage.content || "None");
    EditEmbed.setFooter(`Message ID: ${oldMessage.id} | Author ID: 
        ${oldMessage.author.id}`);

    const EditChannel = messageUpdate.guild.channels.find(x => x.name 
       === "audit");
    EditChannel.send(EditEmbed);
});

CodePudding user response:

In [email protected], the way that inputs were changed.

const { EmbedBuilder } = require("discord.js");
const embed = new EmbedBuilder()
  .setAuthor({ name: "String", iconURL: "URL" })
  .setTitle("String")
  .setDescription("String")
  .setColor("String // RGB or Designated Color")
  .addFields(
    { name: "String", value: "String },
    { name: "String", value: "String" },

  )
  .setFooter({ text: "String", iconURL: "URL" })
  .setTimestamp()

Though I'm not too certain about the .addField() method, since I use .addFields() no matter the circumstance, this should be correct. Either way, you can always look at the EmbedBuilder documentation.

https://discord.js.org/#/docs/builders/main/class/EmbedBuilder

Hope this helps.

  • Related