我一直在尝试使我的机器人的嵌入颜色动态更新(使用随机颜色,编辑 HSV value)。但是,使用 msg.embeds[0]
似乎给了我之前显示的嵌入。
这是我的代码片段:
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] });
});
我正在使用 color-convert
库和 https://stackoverflow.com/a/35467449/11690210 脚本(减去 substr()
)来编辑颜色。我对机器人还是很陌生,所以我可能错过了一些东西。我该如何修复/改进它?如果需要,我很乐意分享更多信息。
回答1
我修复了它,在交互过程中必须将 msg =
放在 msg.edit()
前面,以使其保持在 date 上。
await i.deferUpdate();
await wait(0);
msg = await msg.edit({ embeds: [newEmbed], components: [row] });