1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Telegram Message AutoForward using Python

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to auto-forward a message from one group to another group of telegram using python. Currently this works when i run this. It forwards the last message from group A to group B. Need help with creating a loop wherein this works automatically. Whenever there is a new message which comes in Group A, it should get forwarded to Group B

    api_id = 123456
    api_hash = '5ad488f'
    source_chat_id = -1000000000
    destination_chat_id = -10000000000
    with TelegramClient('my_session', api_id, api_hash) as client:
    chat = client.get_entity(source_chat_id)

    last_message_id = (client.get_messages(source_chat_id, limit=1))[0].id
    print(last_message_id)

    message = client.iter_messages(chat, limit=1)
    for message in client.get_messages(source_chat_id, limit=1):
    if message.id == last_message_id:
    client.send_message(destination_chat_id, message.text)
    print("Message forwarded")
    last_message_id = max(last_message_id, message.id)

    Continue reading...

Compartilhe esta Página