Discord.js Embed Editing V12

I want to make One embed turn into The second embed when someone reacts with the thumbs up, but ever attempt at this has failed…

    const Discord = require("discord.js");

module.exports = {
  name: "start",
  description: "this is a shop command!",
  execute(message, args) {
    const embed = new Discord.MessageEmbed()
      .setTitle("The Diner | Start")
      .setColor("#12e080")
      .setThumbnail(
        "https://cdn.glitch.com/494de277-06ea-4e76-95eb-1d9d87a0e5a4%2Funknown%20(2).png?v=1598630444256"
      )
      .addFields({
        name: `${message.author.username}, **ARE YOU SURE?**`,
        value: `${message.author.username}, You can only use this command once, and once you use it you will start your own restaurant that **you and you alone will have to manage!**`,
        inline: true
      })
      .setFooter("Start your restaurant today!");
    message.channel.send(embed).then(sentEmbed => {
      sentEmbed.react("πŸ‘");
      sentEmbed.react("πŸ‘Ž");
      const filter = (reaction, user) => {
        return (
          ["πŸ‘", "πŸ‘Ž"].includes(reaction.emoji.name) &&
          user.id === message.author.id
        );
      };

      sentEmbed
        .awaitReactions(filter, { max: 1, time: 30000, errors: ["time"] })
        .then(collected => {
          const reaction = collected.first();

          if (reaction.emoji.name === "πŸ‘") {

            const embed2 = new Discord.MessageEmbed()
             //embed stuff
              message.edit(embed2).then(sentEmbed => {
              sentEmbed.react("🍝");
              sentEmbed.react("πŸ₯―");
              sentEmbed.react("🍨");
              sentEmbed.react("πŸ§‡");
              sentEmbed.react("πŸ₯ž");
              sentEmbed.react("πŸ‹");
              sentEmbed.react("🍚");
              sentEmbed.react("πŸ₯©");
              sentEmbed.react("πŸ•");
              sentEmbed.react("πŸ”");

              const filter = (reaction, user) => {
                return (
                  [
                    "🍝",
                    "πŸ₯―",
                    "🍨",
                    "πŸ§‡",
                    "πŸ₯ž",
                    "πŸ‹",
                    "🍚",
                    "πŸ₯©",
                    "πŸ•",
                    "πŸ”"
                  ].includes(reaction.emoji.name) &&
                  user.id === message.author.id
                );
              };

              sentEmbed
                .awaitReactions(filter, {
                  max: 1,
                  time: 60000,
                  errors: ["time"]
                })
                .then(collected => {
                  const reaction = collected.first();

                  if (reaction.emoji.name === "🍝") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Italian Restaurant!`
                    );
                  }
                  if (reaction.emoji.name === "🍨") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Ice Cream Truck!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ§‡") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Waffle House!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ₯ž") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Pancake Place!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ₯―") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Donut Shop!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ‹") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Lemonade Stand!`
                    );
                  }
                  if (reaction.emoji.name === "🍚") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Asian Grill!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ₯©") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Steak House!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ•") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Pizzaria!`
                    );
                  }
                  if (reaction.emoji.name === "πŸ”") {
                    message.channel.send(
                      `"${message.author.username}", You have selected the Burger Place!`
                    );
                  } 
                })
                .catch(collected => {
                  message.reply(
                    `Are you listening? You didn't answer the question!`
                  );
                });
            });
          }
        })
        .catch(collected => {
          message.reply(`Are you listening? You didn't answer the question!`);
        });
    });
  }
};

Any idea how to fix this?

First could you edit your sent code a little? We don’t need the entire contents of mechanics of embed2.

I think your problem would be in
message.edit(embed2)
What do the discord.js docs say about using message.edit? You might be missing some parameters.

To edit the content of an embed you need to pass a new MessageEmbed structure or embed object to the messages .edit() method.

const exampleEmbed = new Discord.MessageEmbed()
	.setTitle('Some title')
	.setDescription('Description after the edit');

message.edit(exampleEmbed)

This is all it says.

Edit for anyone coming to this post in the future: use this answer.

old answer

You’re trying to edit the message object which is defined as the received discord message, not one your client has sent.

You should change

 message.channel.send(embed).then(sentEmbed => {
//rest of your code

to

const msg = message.channel.send(embed).then(sentEmbed => {
//rest of your code

You would then need to change

message.edit(embed2).then(sentEmbed => {
//rest of your code

to

msg.edit(embed2).then(sentEmbed => {
//rest of your code

Note that this is just what I’ve seen off a quick glance at the code. It may not be 100% accurate.

So when i did that it gave the
message.reply(`Are you listening? You didn't answer the question!`);
Part

Edit: It sent that message

Lol scrap the above answer I wrote, I just tested the command and realized you can replace

message.edit(embed2).then(sentEmbed => {

with

sentEmbed.edit(embed2).then(sentEmbed => {
/* I'd recommend renaming the second sentEmbed variable to something else btw. */

and it should :tm: work.

3 Likes

OMG THANK YOU! i’ve searched for an answer for like 2 days now!

3 Likes

i have a error that at long time turn the bot off

(node:20264) UnhandledPromiseRejectionWarning: #
(Use node --trace-warnings ... to show where the warning was created)
(node:20264) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line options | Node.js v15.8.0 Documentation). (rejection id: 1)
(node:20264) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:20264) UnhandledPromiseRejectionWarning: #
(node:20264) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line options | Node.js v15.8.0 Documentation). (rejection id: 2)

Hey there! Please dont bump old posts. Create yourself a new in #discord-help!

2 Likes