使嵌入在一段时间内改变颜色 discord.js

making the embed change color during a time discord.js

    case 'test':
      let timed = "10s"
      const tests = new Discord.RichEmbed()
      .setTitle("tets")
      .setColor('#000000')

      message.channel.send(tests);
      setTimeout(function(){
      tests.setColor('#5e4242')
      }, ms(timed));

      break;

所以我试图让嵌入的颜色在 10 秒后改变,这是一个测试命令,所以它被称为 test.I 尝试了很多方法,我搜索了 google 并且它显示了这个所以我决定尝试一下,它完全 nothing.I 使用 richembed 因为当我使用 messagemebed 时它说客户端错误

发送消息后设置颜色将编辑对象,但不会编辑该消息,您可以使用相同的消息对象编辑消息,但也要更改颜色

    let timed = "10s"
      const tests = new Discord.RichEmbed()
      .setTitle("tets")
      .setColor('#000000');

    var testMsg = message.channel.send(tests).then(
      setTimeout(function(){
         tests.setColor('#5e4242');
         testMsg.edit(tests); // edit the message with the same object but different color
      }, ms(timed));
)

      break;

您需要将发送的消息设置到变量中,然后编辑该消息。

  let timed = "10s"
  const tests = new Discord.RichEmbed()
  .setTitle("tets")
  .setColor('#000000')

  const res = await message.channel.send(tests);
  setTimeout(function(){
     tests.setColor('#5e4242');
     res.edit(tests);
  }, ms(timed));

还应注意,await 仅适用于异步函数

这里是V12版本

    let embed = new Discord.MessageEmbed()
    .setColor('#ffffff')
    .setTitle('I am a colour-changing embed')

    let msg = await message.channel.send(embed)
setTimeout(() => {
     embed.setColor('#5e4242');
     msg.edit(embed);
  }, /*Delay*/);

这段代码创建了一个新的嵌入,然后创建了一个 let 变量,该变量发送消息 [有点像发送带有标签的消息]。然后它使用嵌入变量编辑颜色并在延迟后编辑之前的消息。