'Discord.js get current message embed
I've been trying to make my bot's embed color update dynamically (using random color, editing HSV value). However, using msg.embeds[0] seems to give me the previous shown embed.
Here's a snippet of my code:
collector.on('end', () => {
currentEmbed = msg.embeds[0]
const rowAgain = msg.components[0]
for (c of rowAgain.components) {
c.disabled = true;
}
let colorHex = `#${vb2Hex(currentEmbed.color)}`;
const colorHsv = hex.hsv(colorHex);
const val = colorHsv[2] - 5;
colorHsv.splice(2, 1, val);
colorHex = hsv.hex(colorHsv);
color = parseInt(colorHex, 16);
currentEmbed.color = color;
msg.edit({ embeds: [currentEmbed], components: [row] });
});
I'm using the color-convert library and this script (minus the substr()) to edit the colors. I'm still new-ish to bots, so I might've missed something. How can I fix/improve it? I'll gladly share more info if needed.
Solution 1:[1]
I fixed it, had to put msg = in front of msg.edit() during an interaction to keep it up to date.
await i.deferUpdate();
await wait(0);
msg = await msg.edit({ embeds: [newEmbed], components: [row] });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
