вот я кидаю в телеграме альбом из трех к примеру картинок и у одной из них есть текст, и…
- User
вот я кидаю в телеграме альбом из трех к примеру картинок и у одной из них есть текст, и у меня не копируется альбом с текстом а просто медиа, без текста и из-за этого не удаляется то что я скопировал и еще и без текста надеюсь ты понял
from aiogram import Router, Bot, types, F from aiogram.filters import Command, CommandObject
router_duplicate = Router()
MAX_SIZE_TEXT = 200 COPY_INFO = """/copy, /replace - copy the message by replying to the message
async def _edit_message_text_or_caption(bot: Bot, message: types.Message, new_text: str, new_entities: list): """Edits either the text or caption of a message, depending on its content.""" if message.text: await bot.edit_message_text( message_id=message.message_id, chat_id=message.chat.id, text=new_text, entities=new_entities, parse_mode=None ) else: await bot.edit_message_caption( message_id=message.message_id, chat_id=message.chat.id, caption=new_text[:1024], caption_entities=new_entities, parse_mode=None )
async def _copy_or_forward_and_delete(bot: Bot, message: types.Message, forward=False): if forward: """Forwards a message and then deletes the original.""" await bot.forward_message( chat_id=message.chat.id, from_chat_id=message.chat.id, message_id=message.message_id, message_thread_id=message.message_thread_id if message.is_topic_message else None ) else: """Copies a message and then deletes the original.""" await bot.copy_message( chat_id=message.chat.id, from_chat_id=message.chat.id, message_id=message.message_id, message_thread_id=message.message_thread_id if message.is_topic_message else None, caption=message.caption, ) try: await bot.delete_message(message.chat.id, message.message_id) except Exception as ex: print("_copy_or_forward_and_delete(Error deleting message): ", ex)
async def edit_message_or_caption(bot: Bot, message: types.Message, command: CommandObject): """Edits the text or caption of a replied message, adjusting entity offsets.""" reply = message.reply_to_message text = command.args entities = [ types.MessageEntity( type=e.type, offset=e.offset - len(command.command) + 2, length=e.length, url=e.url, user=e.user, language=e.language, custom_emoji_id=e.custom_emoji_id, ) for e in message.entities or [] ] await _edit_message_text_or_caption(bot, reply, text, entities)
@router_duplicate.message(Command("copy", "replace")) async def handle_copy_replace_command(message: types.Message, command: CommandObject, bot: Bot): reply = message.reply_to_message if not reply or reply.forum_topic_created: return await message.reply(COPY_INFO)
code - Assistant