discord - Discord.js 获取当前消息嵌入

我一直在尝试使我的机器人的嵌入颜色动态更新(使用随机颜色,编辑 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] });

相似文章

html - CSS 响应式容器到文本

我在编程方面仍然相对缺乏经验,这就是我问这个问题的原因。我有一个带有backgroundimage的部分,其中包含文本;文本也占用了它需要的空间,但不幸的是backgroundimage与文本不匹配,...

随机推荐

最新文章