def painttest(update, context): def outtext(text): if edt_msg: try: msg = context.bot.edit_message_text(chat_id = update.edited_message.chat.id, message_id = replys[update.edited_message.chat.id],text=text) except telegram.error.BadRequest: context.bot.delete_message(chat_id = update.edited_message.chat.id, message_id = replys[update.edited_message.chat.id]) msg = update.edited_message.reply_text(text) return msg else: return update.message.reply_text(text) def outphoto(filename): fn = os.path.basename(filename.rstrip(os.sep)) if edt_msg: try: msg = context.bot.edit_message_media(chat_id=update.edited_message.chat.id,message_id=replys[update.edited_message.chat.id],media=telegram.InputMediaPhoto(filename=fn,media=open(filename, 'rb'))) except telegram.error.BadRequest: context.bot.delete_message(chat_id = update.edited_message.chat.id, message_id = replys[update.edited_message.chat.id]) msg = update.edited_message.reply_photo(filename=fn,photo=open(filename, 'rb')) return msg else: return update.message.reply_photo(filename=fn,photo=open(filename, 'rb')) try: text = update.message.text edt_msg = False except AttributeError: text = update.edited_message.text edt_msg = True