Ошибка: Бот запущен. Ожидание новых сообщений... Найдена кнопка '' в сообщении, нажимаю... Unhandled exception on handler Traceback (most recent call last): File "/root/venv/lib/python3.12/site-packages/telethon/client/updates.py", line 570, in _dispatch_update await callback(event) File "/root/майнг/bot.py", line 39, in handler await process_message(event) File "/root/майнг/bot.py", line 29, in process_message reply_to=InputReplyToMessage(id=message.id), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: InputReplyToMessage.__init__() got an unexpected keyword argument 'id' Код: import asyncio from telethon import TelegramClient, events from telethon.tl.types import KeyboardButtonCallback, ReplyInlineMarkup, InputReplyToMessage from telethon.tl import functions # Замените на свои значения api_id = api_hash = '' bot_token = '' channel_id = -1002359327215 target_text = "Для начисления нажмите на кнопку:" target_button_text = "" client = TelegramClient('anon', api_id, api_hash).start(bot_token=bot_token) async def process_message(event): message = event.message if target_text in message.text: if message.reply_markup and message.reply_markup.rows: for row_index, row in enumerate(message.reply_markup.rows): for button_index, button in enumerate(row.buttons): if isinstance(button, KeyboardButtonCallback) and button.text == target_button_text: print(f"Найдена кнопка '{target_button_text}' в сообщении, нажимаю...") await client( functions.messages.SendMessageRequest( peer=message.peer_id, message=target_button_text, reply_to=InputReplyToMessage(id=message.id), reply_markup=ReplyInlineMarkup(rows=[[KeyboardButtonCallback(text=target_button_text, data=button.data)]]) ) ) print("Кнопка нажата.") return print(f"Сообщение '{target_text}' найдено, но кнопка '{target_button_text}' не найдена.") @client.on(events.NewMessage(chats=[channel_id])) async def handler(event): await process_message(event) async def main(): print("Бот запущен. Ожидание новых сообщений...") await client.run_until_disconnected() if __name__ == '__main__': client.loop.run_until_complete(main()) Python import asyncio from telethon import TelegramClient, events from telethon.tl.types import KeyboardButtonCallback, ReplyInlineMarkup, InputReplyToMessage from telethon.tl import functions # Замените на свои значения api_id = api_hash = '' bot_token = '' channel_id = -1002359327215 target_text = "Для начисления нажмите на кнопку:" target_button_text = "" client = TelegramClient('anon', api_id, api_hash).start(bot_token=bot_token) async def process_message(event): message = event.message if target_text in message.text: if message.reply_markup and message.reply_markup.rows: for row_index, row in enumerate(message.reply_markup.rows): for button_index, button in enumerate(row.buttons): if isinstance(button, KeyboardButtonCallback) and button.text == target_button_text: print(f"Найдена кнопка '{target_button_text}' в сообщении, нажимаю...") await client( functions.messages.SendMessageRequest( peer=message.peer_id, message=target_button_text, reply_to=InputReplyToMessage(id=message.id), reply_markup=ReplyInlineMarkup(rows=[[KeyboardButtonCallback(text=target_button_text, data=button.data)]]) ) ) print("Кнопка нажата.") return print(f"Сообщение '{target_text}' найдено, но кнопка '{target_button_text}' не найдена.") @client.on(events.NewMessage(chats=[channel_id])) async def handler(event): await process_message(event) async def main(): print("Бот запущен. Ожидание новых сообщений...") await client.run_until_disconnected() if __name__ == '__main__': client.loop.run_until_complete(main())
Ритик, Бот запущен. Ожидание новых сообщений... Найдена кнопка '' в сообщении, нажимаю... Unhandled exception on handler Traceback (most recent call last): File "/root/venv/lib/python3.12/site-packages/telethon/tl/tlobject.py", line 194, in __bytes__ return self._bytes() ^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/tl/functions/messages.py", line 7081, in _bytes b'' if self.reply_markup is None or self.reply_markup is False else (self.reply_markup._bytes()), ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/tl/types/__init__.py", line 29388, in _bytes b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.rows)),b''.join(x._bytes() for x in self.rows), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/tl/types/__init__.py", line 29388, in <genexpr> b'\x15\xc4\xb5\x1c',struct.pack('<i', len(self.rows)),b''.join(x._bytes() for x in self.rows), ^^^^^^^^ AttributeError: 'list' object has no attribute '_bytes' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/root/venv/lib/python3.12/site-packages/telethon/client/updates.py", line 570, in _dispatch_update await callback(event) File "/root/майнг/bot.py", line 40, in handler await process_message(event) File "/root/майнг/bot.py", line 26, in process_message await client( File "/root/venv/lib/python3.12/site-packages/telethon/client/users.py", line 30, in __call__ return await self._call(self._sender, request, ordered=ordered) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/client/users.py", line 67, in _call future = sender.send(request, ordered=ordered) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/network/mtprotosender.py", line 183, in send state = RequestState(request) ^^^^^^^^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/network/requeststate.py", line 17, in __init__ self.data = bytes(request) ^^^^^^^^^^^^^^ File "/root/venv/lib/python3.12/site-packages/telethon/tl/tlobject.py", line 200, in __bytes__ raise TypeError('a TLObject was expected but found something else') TypeError: a TLObject was expected but found something else
Первую проблему, я так понял, ты решил, вот решение второй Проблема в том, как формируется reply_markup . В текущем коде создается неправильная структура для кнопок. Нужно использовать KeyboardButtonRow для создания строк кнопок. Вот исправленный код: from telethon.tl.types import ( KeyboardButtonCallback, ReplyInlineMarkup, InputReplyToMessage, KeyboardButtonRow ) async def process_message(event): message = event.message if target_text in message.text: if message.reply_markup and message.reply_markup.rows: for row_index, row in enumerate(message.reply_markup.rows): for button_index, button in enumerate(row.buttons): if isinstance(button, KeyboardButtonCallback) and button.text == target_button_text: print(f"Найдена кнопка '{target_button_text}' в сообщении, нажимаю...") # Создаем правильную структуру кнопок button_row = KeyboardButtonRow([ KeyboardButtonCallback(text=target_button_text, data=button.data) ]) await client( functions.messages.SendMessageRequest( peer=message.peer_id, message=target_button_text, reply_to=InputReplyToMessage(reply_to_msg_id=message.id), reply_markup=ReplyInlineMarkup(rows=[button_row]) # Используем структуру с KeyboardButtonRow ) ) print("Кнопка нажата.") return print(f"Сообщение '{target_text}' найдено, но кнопка '{target_button_text}' не найдена.") Python from telethon.tl.types import ( KeyboardButtonCallback, ReplyInlineMarkup, InputReplyToMessage, KeyboardButtonRow ) async def process_message(event): message = event.message if target_text in message.text: if message.reply_markup and message.reply_markup.rows: for row_index, row in enumerate(message.reply_markup.rows): for button_index, button in enumerate(row.buttons): if isinstance(button, KeyboardButtonCallback) and button.text == target_button_text: print(f"Найдена кнопка '{target_button_text}' в сообщении, нажимаю...") # Создаем правильную структуру кнопок button_row = KeyboardButtonRow([ KeyboardButtonCallback(text=target_button_text, data=button.data) ]) await client( functions.messages.SendMessageRequest( peer=message.peer_id, message=target_button_text, reply_to=InputReplyToMessage(reply_to_msg_id=message.id), reply_markup=ReplyInlineMarkup(rows=[button_row]) # Используем структуру с KeyboardButtonRow ) ) print("Кнопка нажата.") return print(f"Сообщение '{target_text}' найдено, но кнопка '{target_button_text}' не найдена.") Основные изменения: 1. Добавлен импорт KeyboardButtonRow 2. Создается правильная структура кнопок с использованием KeyboardButtonRow 3. Кнопки группируются в строку перед добавлением в ReplyInlineMarkup Это должно исправить ошибку TypeError, связанную с неправильной структурой объекта TL.