user11888265
user11888265

Reputation: 25

How can I make my discord bot edit its own last message after data is ready

My discord bot has a command to lookup data from an API and sometimes it takes time so I want my bot to tell the user that.

The initial message is: message.channel.send({embed: { color: 0x80ff00, description: "Looking for data"}})

How can I make the bot edit the message with the data after the data embed is ready?

Upvotes: 1

Views: 1975

Answers (2)

PLASMA chicken
PLASMA chicken

Reputation: 2785

Using .then:

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

Using async await:

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

Upvotes: 1

Aurel Bílý
Aurel Bílý

Reputation: 7963

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}});
    });
  });

See TextChannel#send and Message#edit.

Upvotes: 1

Related Questions