Editing RichEmbeds

Hello everyone. I’ll just skip straight to the point.

I’m wondering how to edit an already sent rich embed. I’ve managed to make an embed with a title, description, image and all that, but I want it so that when you react with a specific reaction, the embed changes to the next “page”. I’ve made arrays with the data I want to change, and increase the number of which object in the array is sent. All that remains is actually updating the embed.

if(command === “buy”) {
var car = [“Toyota Corolla Sedan”, “Ferrari F8 Tributto”, “Pz 1 C Tank”, “Roblox car”, “Minecart”, “Lamborghini Egoista”] //Toyota Corolla sedan, Ferrari f8 tributto
var image = [‘https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2FScreenshot%202019-10-16%20at%2021.20.39.png?v=1571253659527’,
https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2F08a18b3b-d131-4eaf-bb5e-7b83a8149398.image.png?v=1571253723377’,
https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2F247c2bde-e3fa-42fb-a597-1d2ccccf2bf6.image.png?v=1571299572407’,
https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2F55ddbd9e-b6ab-4ec1-a239-d487e39bc19b.image.png?v=1571299596686’,
https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2F93565686-bbd6-462b-b469-a72a586d6765.image.png?v=1571299625709’,
https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2Fc0396080-1337-4712-83dc-5db16482be9d.image.png?v=1571299645225’]
var cs = 0
var price = [5000, 200000, 50000, 10000, 20000, 10000000]
const shop = new Discord.RichEmbed()
.setTitle(“Owned by the Monimuffin Server”)
.setAuthor(“A fucking car shop!”, “https://cdn.glitch.com/bdd2abbd-8294-4499-912d-00f9d20e3a1e%2Fa_cf72f7bf4419755aefe87ac271108514.gif?v=1571297404455”)
.setDescription(car[cs])
.setColor(0x00AE86)
.setImage(image[cs])
.addField(“Price”, price[cs] + “$”)
message.channel.send(shop).then(sentEmbed => {
sentEmbed.react(“:arrow_left:”)
sentEmbed.react(“:moneybag:”)
sentEmbed.react(“:arrow_right:”)
})
const filter = (reaction, user) => {
return [‘:arrow_right:’, ‘:arrow_left:’, ‘:moneybag:’].includes(reaction.emoji.name) && user.id === message.author.id;
};
message.awaitReactions(filter, {time: 60000})
.then(collected => {
console.log(“received”)
const reaction = collected.first();
if (reaction.emoji.name == ‘:arrow_right:’) {
console.log(cs)
cs++
if(cs>=6) {
var cs = 0
}
message.delete(1)
message.channel.send(shop)
}
else if(reaction.emoji.name === ‘:arrow_left:’) {
cs–
if(cs<=-1) {
var cs = 5

Here is a simple way of editing rich embeds:

let firstEm=new Discord.RichEmbed()
     .addField("test", "hi");
message.channel.send(firstEm).then(msg => {
 let secondEm = new Discord.RichEmbed()
     .addField("hello", "hi");
  setTimeout(async()=>{
   msg.edit(secondEm)
  }, 1000) // ms until message is edited with new embed
})

the same message will be edited, with the new embed

2 Likes

So basically change from const to let, make a new embed to replace the old one and apply that as a value to the let. After that you just do message.edit(let-variable)?

Thanks, it works now

1 Like