skip to Main Content
from telethon import TelegramClient, events, sync
client.start()
destination_group_invite_link=grouplink #t.me/xxxxxxx
entity=client.get_entity(destination_group_invite_link)
client.send_file(entity=entity, message="xxxx")

With this code I can send message to public linked group. But how do I send a message to a group with a private link?

#t.me/+xxxxxxxxx

3

Answers


  1. Chosen as BEST ANSWER

    Here are all my codes. I don't understand how to do what you said man. @kekkoilmedikit

    from telethon import TelegramClient, events, sync
    import re
    from colorama import Fore, Back, Style, init
    import time
    api_id = ....
    api_hash = ''
    client = TelegramClient('anon', api_id, api_hash)
    group = input(Fore.CYAN + "Group Name >>>>> ")
    second = input(Fore.CYAN + "Second >>>>> ")
    secenek = input(Fore.CYAN + """
    Press 1 to Send Message!
    
    Press 2 to Send Picture!
    
    >>>>>>>>>>>>>>>>>>>>>>>  """)
    if (float(secenek) == 1):
      send = input(Fore.RED + " Enter Message to Send >>>>> ")
      while(True):
        init(autoreset=True)
        client.start()
        destination_channel_username=group
        entity=client.get_entity(destination_channel_username)
        client.send_message(entity=entity,message=send)
        time.sleep(float(second))
    if (float(secenek) == 2):
      send = input(Fore.RED + " Gönderilcek Resmin Yolunu Giriniz >>>>> ")
      while(True):
        init(autoreset=True)
        client.start()
        destination_channel_username=group
        entity=client.get_entity(destination_channel_username)
        client.send_file(entity=entity, file=send)
        time.sleep(float(second))
    

  2. first, you need to join the group, to do so:

    from telethon.tl.functions.messages import ImportChatInviteRequest
                                                    ^
                                                    |      
                                        (this will throw an error you are already in the group)
    

    if you are already inside of the group:

    from telethon.tl.functions.messages import CheckChatInviteRequest
    

    code with ImportChatInviteRequest:

     update = await client(ImportChatInviteRequest("Group link"))
                group_to_search = (update.chats.Chat.id)
    

    code with CheckChatInviteRequest: [for this you need the group link, specifically the hash, to find it you need to to replace "https://t.me/+" with a blank space]

    group_to_search = await client(CheckChatInviteRequest(hash = link_to_search))
                group_to_search = str(group_to_search.chat.id)
    
    Login or Signup to reply.
  3. I Solved the Problem.

    Just specify the id of the group as the target. And it works 🙂 Thanks for the @kekkoilmedikit help

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search