Home > Mobile >  How to edit a last bot send
How to edit a last bot send

Time:06-21

I need to edit the last message from bot. But I don't know how get ID of last sended messade. This code

bot.hears('hi', async (ctx) =>{
  try{
    await ctx.reply('hello')
    ctx.editMessageText(ctx.from.id, ctx.from.message.id, "second text")
  }catch(e){
    console.log(e)
  }
})

give me this result:

TypeError: Telegraf: "editMessageText" isn't available for "message"

CodePudding user response:

The ID is included in the return value of ctx.reply.

You can then use it like this:

const { message_id } = await ctx.reply('hello');

// use message_id

Here's an example:

const { message_id } = await ctx.reply('hello');
await new Promise(r => setTimeout(r, 3000);
await ctx.telegram.editMessageText(ctx.chat.id, message_id, 0, 'new text');
  • Related