Advertisement
askanton

Два телеграм аккаунта в одном скрипте

Mar 28th, 2021
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. from telethon import TelegramClient, events
  2.  
  3. api_id =       *******                                     #user1
  4. api_hash =     "********************************"          #user1
  5. api_id2 =      *******                                     #user2
  6. api_hash2 =    "********************************"          #user2
  7. chat_to_send = -1001********
  8.  
  9. client1 = TelegramClient('my_account', api_id, api_hash)
  10. client2 = TelegramClient('user2', api_id2, api_hash2)
  11. print("************************************************************************")
  12. async def sender(mess):
  13.     await client2.start()
  14.     username = await client2.get_me()
  15.     print("Working under: ", username.username)
  16.     try:
  17.         await client2.send_message(chat_to_send, mess.message)
  18.     except Exception as e:
  19.         print(e)
  20.     print("Message resend")
  21.     print("************************************************************************")
  22.  
  23. @client1.on(events.NewMessage)
  24. async def my_event_handler(event):
  25.     print("Resend started")
  26.     username = await client1.get_me()
  27.     print("Working under: ", username.username)
  28.     try:
  29.         print("Channel busted: ", event.message.peer_id.channel_id)
  30.         await sender(event)
  31.     except Exception as e:
  32.         print(e)
  33.         try:
  34.             print("Chat busted: ", event.message.peer_id.chat_id)
  35.             await sender(event)
  36.         except Exception as e:
  37.             print(e)
  38.             print("Dialog busted")
  39.  
  40.  
  41.  
  42.  
  43. client1.start()
  44. client1.run_until_disconnected()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement