Answer the question
In order to leave comments, you need to log in
How can a bot change a message?
How to make a telegram bot change messages
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await bot.send_message(message.chat.id, 'Ждем: 2сек')
await sleep(1)
await bot.edit_message_text(chat_id=message.chat.id, message_id=message.message_id, text='Ждем: 1сек')
await sleep(1)
await bot.edit_message_text(chat_id=message.chat.id, message_id=message.message_id, text='Готово')
Answer the question
In order to leave comments, you need to log in
message in this function is the message of the user who wrote /start. Then the bot tries to edit this message... and it doesn't work! Of course, because he can only edit his own messages, but not others.
He should just edit his own post, not the user's post:
my_new_message = await bot.send_message(message.chat.id, 'Ждем: 2сек')
await sleep(1)
await bot.edit_message_text(chat_id=message.chat.id, message_id=my_new_message.message_id, text='Ждем: 1сек')
...
First you need to take your first message and shove it into a variable and manage to send it using this line:
m = await bot.send_message(message.chat.id, 'Ждем: 2сек')
await m.edit(content = "Ждем: 1сек")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question