How to make a Telegram members adding script



We are going to scrape Telegram group members and add it to your own group. We will also use a bunch of techniques to be able to add unlimited members to your Telegram group by bypassing Telegram limitations that suppresses the process after adding 50 members. this article includes Telegram group member extractor tutorial and also inclues the python code of Telegram group member adder so you will be able to copy Telegram group members.

Step 1: Obtain API ID and API HASH

In order to communicate with Telegram API, we are required to obtain API ID and API HASH from My Telegram page.

Step 2: Export competitor group members

Visit the tutorial here to learn to export members from a Telegram group.

Step 3: Creating multiple accounts for adding members and how to bypass the adding limits

In case you don't know, there are many factors that effect the number of members each account can add everyday.

  • Which country to use for making accounts?
    One of the most important factors is the country that the simcart belongs to. Countries like USA, Spain, Netherlands, Sweden have by far the best virtual numbers for creating accounts and adding members. There are many websites out there that sell virtual numbers for very cheap and reasonable prices. however it is recommend to use real simcarts if possible.
  • Can my API ID and API HASH get poisoned and detected as spammer?
    Another factor that is important, is the API ID and API HASH that you use for creating accounts. Incase those API credentials are poisoned (detected as unusual or spammy behavior), you will have to obtain new ones from a new account because each account can only have one pair of API ID and API HASH.
  • Is it safe to add a lot members to a single group in a short time?
    Another factor is relevant to how you use the numbers, if you add many members to a group in one single day, the chances are that many of those members report the group spam and this might make the Telegram spam detection algorithms ban the adder accounts or even the group itself might get deleted! So you need to be cautious with this process.
  • What should I do when the account gets flooded?
    Please note that if an account (session) is flooded, there is a high chance that it might get pure again after 10 minutes, 12 hours or 3 days. However spammy accounts tend to get deleted after hitting a flood error caused by adding members. In case a number is detected as a spammer by Telegram, deleting that account and registering again won't help to purify the spam flag on that account.
  • What should I do if every account I make gets Deleted (Deleted Account) after using it for adding members?
    In such cases, create your accounts using an Official version of Telegram (Telegram for iOS, Android, etc) and wait for 3 days. after 3 days, make a session out of the account. This will make the account stronger.
  • What other things matter in creating accounts?
    Based on my personal experience, the creator of a group also effects the way you can add members to that group. Like groups there are created by Asian accounts might not get members that are from other continents. For example a group from India has a very hard time accepting members from European countries. So if you try to add (European) members to such (Indian) groups your accounts are very likely to get deleted! This applies to many Asian groups from different countries as well.


from telethon import TelegramClient, sync
client = TelegramClient(SESSION_FILE_NAME, API_ID, 'API_HASH')
client.start()

This will create a session out of the number you enter (after running the python file) and saves the session into a file named SESSION_FILE_NAME for future use (adding members!). Remember to change the SESSION_FILE_NAME each time you make a new session so you won't overwrite the previous one!

Step 4: Adding members to your own group using the sessions you have created

Ok here we go! Our script iterates over all the session that you have created and will use them one by one to add members until they get flooded or banned or stopped by any kind of terminating exception. Let's import the required modules first.

import logging
import time
import random
import os
from telethon import TelegramClient, sync, connection
from telethon.errors.rpcerrorlist import FloodWaitError
from telethon.errors.rpcerrorlist import FloodError, UserAlreadyParticipantError, InviteHashInvalidError, InviteHashExpiredError


Now we write a single line of code to collect all session files (all accounts) that are in the current folder

all_sessions = [x for x in os.listdir('.') if 'session' in x and 'journal' not in x]

Now lets iterate through all sessions using a for loop, and connect to the API!

for session in sessions:
    client = TelegramClient(session.split('.')[0], API_ID, 'API_HASH')
    try:
        client.connect()
        me = client.get_me()
        if not me:
          continue
    except ConnectionError:
         continue


Now that we are connected to the API, lets get the group details we are trying to add members to and join it!

group = client.get_entity('https://t.me/your_group_public_username')
client(JoinChannelRequest(group))


We joined the group! Now lets add the members we have in our list to the our group! We're going to open the file, read each line (each line is a user we want to add). and try adding the user to the group. In case we get any flood errors as the exception, we switch the account to add the rest of members using a fresh session!

with open(members_file, 'r') as the_file:
    members = the_file.read().split('\n')
    for m in members:
        if switch_account == True:
            break
        try:
             client(InviteToChannelRequest(group, [m]))
        except Exception as ex:
            if any(s in str(ex) for s in ['Too many', 'deleted/deactivated', 'banned', 'seconds is required', 'USER_DEACTIVATED_BAN', 'write in this chat']):
                switch_account = True





Author: Amin Etesamian


204 Comments

Leave a Comment