pyrogram
pyrogram copied to clipboard
Error editing message (Error 400 - 'Bad Request: MESSAGE_ID_INVALID') with ReplyKeyboardRemove markup
Checklist
- [X] I am sure the error is coming from Pyrogram's code and not elsewhere
- [X] I have searched in the issue tracker for similar bug reports, including closed ones
- [X] I ran
pip3 install -U https://github.com/pyrogram/pyrogram/archive/master.zipand reproduced the issue using the latest development version
Description
Yo. Thank you for the great product. Subj. Although if not remove keyboard it works perfectly.
Steps to reproduce
- Create tg bot, telegram app and put api_id, api_hash, bot_token to code below
- Run code
- Type '/start' to bot
Code example
from pyrogram import Client, filters
from pyrogram.handlers import MessageHandler
from pyrogram.types import ReplyKeyboardMarkup, ReplyKeyboardRemove
api_id = #api_id
api_hash = '#api_hash'
bot_token = '#bot_token'
bot = Client('my_bot', api_id=api_id, api_hash=api_hash, bot_token=bot_token)
def command_start(client, message):
markup = ReplyKeyboardMarkup([['some button']])
bot.send_message(chat_id=message.from_user.id, text='Send you some text with keyboard attached', reply_markup=markup)
new_message = bot.send_message(chat_id=message.from_user.id, text='I remove keyboard', reply_markup=ReplyKeyboardRemove())
# this never runs
new_message.edit(text='Trying to edit last message')
if __name__ == '__main__':
bot.add_handler(MessageHandler(command_start, filters.command("start")))
bot.run()
Logs
Telegram says: [400 MESSAGE_ID_INVALID] - The message id is invalid (caused by "messages.EditMessage")
Traceback (most recent call last):
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/dispatcher.py", line 242, in handler_worker
await self.loop.run_in_executor(
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/andrey/Desktop/music-bot/sss.py", line 15, in command_start
new_message.edit(text='Trying to edit last message')
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/sync.py", line 78, in async_to_sync_wrap
return asyncio.run_coroutine_threadsafe(coroutine, main_loop).result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 446, in result
return self.__get_result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 391, in __get_result
raise self._exception
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/types/messages_and_media/message.py", line 2777, in edit_text
return await self._client.edit_message_text(
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/methods/messages/edit_message_text.py", line 80, in edit_message_text
r = await self.invoke(
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/methods/advanced/invoke.py", line 77, in invoke
r = await self.session.invoke(
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/session/session.py", line 361, in invoke
return await self.send(query, timeout=timeout)
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/session/session.py", line 331, in send
RPCError.raise_it(result, type(data))
File "/home/andrey/Desktop/music-bot/music-bot/lib/python3.10/site-packages/pyrogram/errors/rpc_error.py", line 91, in raise_it
raise getattr(
pyrogram.errors.exceptions.bad_request_400.MessageIdInvalid: Telegram says: [400 MESSAGE_ID_INVALID] - The message id is invalid (caused by "messages.EditMessage")