数据准备好后,如何使Discord机器人编辑自己的最后一条消息

时间:2019-08-06 12:48:53

标签: javascript node.js discord discord.js

我的discord机器人有一个命令可以从API查找数据,有时这需要时间,所以我希望我的机器人告诉用户。

初始消息为:message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})

在数据嵌入准备好后,如何让机器人用数据编辑消息?

2 个答案:

答案 0 :(得分:0)

message.channel
  .send({embed: { color: 0x80ff00, description: "Looking for data"}})
  .then(embed => {
    // here `embed` is the message that was sent to the channel
    someAsyncOperation().then(data => {
      embed.edit({embed: {description: "Found the data: " + data}});
    });
  });

请参见TextChannel#sendMessage#edit

答案 1 :(得分:0)

使用.then:

message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})
    .then(msg => {
        msg.edit('Something');
    });

使用异步等待:

const msg = await message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}});
msg.edit('data');