Reputation: 21
I have written a script to add members to the Telegram group. Function add_members()
return true but memebers not added in my telegram group ,How can I fix the problem?
async def add(client,id , chatid ):
global addcount
try:
noww = await client.add_chat_members(chatid, id)
print(noww)
if noww == True :
addcount = addcount +1
print(f"added member = {addcount}")
await asyncio.sleep(random.randint(8,12))
except FloodWait as e:
print(f"i need to sleep {e.value} second")
await asyncio.sleep(random.randint(8,12))
except UsernameNotOccupied:
print("username not Found!!")
await asyncio.sleep(random.randint(6,10))
except UserNotMutualContact:
print("User Not Mutual Contact!!")
await asyncio.sleep(random.randint(6,10))
except PeerFlood:
print("Account limited !!")
await asyncio.sleep(random.randint(6,10))
except ChatAdminRequired:
print("admin!!")
await asyncio.sleep(random.randint(6,10))
from 40 true add_members()
only 1 user added in my telegram group.
I expected using the function add_member() can add a lot of user in group!
Upvotes: 0
Views: 81
Reputation: 47
A few things need to be checked before adding, like rate limit, permissions, Member Restrictions, etc.
Please try this code to get a better understanding of the exception/error.
import asyncio
import random
from telethon.errors import FloodWait, UsernameNotOccupied, UserNotMutualContact, PeerFlood, ChatAdminRequired
addcount = 0
async def add(client, user_id, chat_id):
global addcount
try:
result = await client.add_chat_members(chat_id, user_id)
print(result)
if result:
addcount += 1
print(f"Added member = {addcount}")
await asyncio.sleep(random.randint(8, 12))
except FloodWait as e:
print(f"FloodWait: Sleeping for {e.seconds} seconds")
await asyncio.sleep(e.seconds)
except UsernameNotOccupied:
print("Username not found!")
await asyncio.sleep(random.randint(6, 10))
except UserNotMutualContact:
print("User not a mutual contact!")
await asyncio.sleep(random.randint(6, 10))
except PeerFlood:
print("PeerFlood: Account limited!")
await asyncio.sleep(random.randint(6, 10))
except ChatAdminRequired:
print("ChatAdminRequired: Admin privileges required!")
await asyncio.sleep(random.randint(6, 10))
except Exception as e:
print(f"Unexpected error: {e}")
await asyncio.sleep(random.randint(6, 10))
Upvotes: 0