Is it possible to change an image inside an embed? I'm trying to recreate an "etch-a-sketch" bot I saw on reddit and was wondering how it was done. Here's what I tried so far: This is inside the function that makes the image:
//code that draws the etch-a-sketch
const etchembed = new Discord.MessageEmbed()
.setAuthor(`${message.author.username}`, `${message.author.displayAvatarURL()}`)
.setTitle('???? Etch-A-Sketch ????')
.setColor("#f66868")
.setFooter(`${client.user.username}`, `${client.user.displayAvatarURL()}`)
//n is a variable that increases by 1 every time the function is run
.attachFiles([new Discord.MessageAttachment(canvas.toBuffer(), `etch${n}.png`)])
.setImage(`attachment://etch${n}.png`)
.setTimestamp();
return etchembed
In the main command file I do this after awaiting for a return from the function:
message.edit(newetchembed)
All this does is move the image outside of the embed. Am I doing something wrong?
Edit 1:
I tried changing message.edit(...) to message.channel.send(...) and it sends a new embed with the right image just fine. When I try to use message.edit, it just moves the image outside of the embed for some reason.
Edit 2:
I did some more testing and I'm starting to think it's just something wrong with discord or discord.js. This is due to the fact that when I log the file attachments and the image, everything works as it should:
embed 1: [
MessageAttachment {
attachment: < Buffer 89 50 4e 47 0 d 0 a 1 a 0 a 00 00 00 0 d 49 48 44 52 00 00 01 94 00 00 01 2 c 08 06 00 00 00 e4 5 c 45 b8 00 00 00 06 62 4 b 47 44 00 ff 00 ff 00 ff a0 bd a7...1167 more bytes > ,
name: 'etch_1595840597644.png'
}
] {
url: 'attachment://etch_1595840597644.png'
}
embed 2: [
MessageAttachment {
attachment: < Buffer 89 50 4e 47 0 d 0 a 1 a 0 a 00 00 00 0 d 49 48 44 52 00 00 01 94 00 00 01 2 c 08 06 00 00 00 e4 5 c 45 b8 00 00 00 06 62 4 b 47 44 00 ff 00 ff 00 ff a0 bd a7...1167 more bytes > ,
name: 'etch_1595840607390.png'
}
] {
url: 'attachment://etch_1595840607390.png'
}
As you can see, the message embeds have different image attachments, so I'm not sure why it just moves the original image outside of the embed instead of attaching a new one. This is what it looks like.
Another thing is that it sends the right image when I send a new message instead of editing.