Sae
Sae

Reputation: 59

Get the message id of a message a bot sent in response

I don't have any code to share as I am just stumped. I know how to get the message id of the message a user sent; for example, if I did !test, I could do message.id to get that id.

But I want to get the id of the message a bot replied with, so if I did !test and a bot replied with "working", I want to get the id of that "working" message. Any ideas?

Upvotes: 1

Views: 898

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23141

You can wait for the message to be sent and grab its ID. send() returns the message, so the following will work:

client.on('messageCreate', async (message) => {
  if (message.author.bot) return;
  let sentMessage = await message.channel.send('It works');
  console.log(sentMessage.id);
});

Upvotes: 1

Related Questions