修复使用电报加法器脚本将用户添加到inPython电报组时出现的错误

修复使用电报加法器脚本将用户添加到inPython电报组时出现的错误,python,try-catch,telegram,telethon,Python,Try Catch,Telegram,Telethon,当我运行脚本时,它以泛洪错误请求结束。请帮助我找到一种方法来修复此代码 请帮助自定义以下代码,使其能够将CSV文件中的电报用户从特定行添加到特定行(即:CSV文件的第13行到第32行)。我需要它,以避免通过在我的频道中添加我的组用户来获得被电报禁止的帐户 SLEEP_TIME_1 = 100 SLEEP_TIME_2 = 100 with client: client.loop.run_until_complete(main()) client.connect() if not clie

当我运行脚本时,它以泛洪错误请求结束。请帮助我找到一种方法来修复此代码

请帮助自定义以下代码,使其能够将CSV文件中的电报用户从特定行添加到特定行(即:CSV文件的第13行到第32行)。我需要它,以避免通过在我的频道中添加我的组用户来获得被电报禁止的帐户

SLEEP_TIME_1 = 100
SLEEP_TIME_2 = 100
with client:
    client.loop.run_until_complete(main())
client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('40779'))

users = []
with open(r"members.csv", encoding='UTF-8') as f:  #Enter your file name
    rows = csv.reader(f,delimiter=",",lineterminator="\n")
    next(rows, None)
    for row in rows:
        user = {}
        user['username'] = row[0]
        user['id'] = int(row[1])
        user['access_hash'] = int(row[2])
        user['name'] = row[3]
        users.append(user)

chats = []
last_date = None
chunk_size = 200
groups = []

result = client(GetDialogsRequest(
    offset_date=last_date,
    offset_id=0,
    offset_peer=InputPeerEmpty(),
    limit=chunk_size,
    hash=0
))
chats.extend(result.chats)

for chat in chats:
    try:
        if chat.megagroup == True:
            groups.append(chat)
    except:
        continue

print('Choose a group to add members: ')
i = 0
for group in groups:
    print(str(i) + '- ' + group.title)
    i += 1

g_index = input("Enter a Number: ")
target_group = groups[int(g_index)]

target_group_entity = InputPeerChannel(target_group.id, target_group.access_hash)


mode = int(input("Enter 1 to add by username or 2 to add by ID: "))

n = 0

for user in users:
    n += 1
    if n % 80 == 0:
        sleep(60)
    try:
        print("Adding {}".format(user['id']))
        if mode == 1:
            if user['username'] == "":
                continue
            user_to_add = client.get_input_entity(user['username'])
            time.sleep(5)
        elif mode == 2:
            user_to_add = InputPeerUser(user['id'], user['access_hash'])
            time.sleep(5)
        else:
            sys.exit("Invalid Mode Selected. Please Try Again.")
        client(InviteToChannelRequest(target_group_entity, [user_to_add]))
        print("Waiting for 60-180 Seconds ...")
        time.sleep(30)
    except PeerFloodError:
        print("Getting Flood Error from telegram. Script is stopping now. Please try again after some time.")
        print("Waiting {} seconds".format(SLEEP_TIME_2))
        time.sleep(SLEEP_TIME_2)
    except UserPrivacyRestrictedError:
        print("The user's privacy settings do not allow you to do this. Skipping ...")
        print("Waiting for 5 Seconds ...")
        time.sleep(10)
    except:
        traceback.print_exc()
        print("Unexpected Error! ")
        continue