from telethon import TelegramClient
from telethon.errors import FloodWaitError
import time
api_id = 'masihpy01_bot'
api_hash = '7735415769:AAFK8RlG_dd4pS7RoWRWgOlmiuvgI9CLGeM'
channel_username = 'masihpy_test'
client = TelegramClient('session_name', api_id, api_hash)
async def remove_all_members(channel):
channel_entity = await client.get_entity(channel)
async for member in client.iter_participants(channel_entity):
try:
print(f'Removing member: {member.first_name} (ID: {member.id})')
await client.kick_participant(channel_entity, member)
time.sleep(1) # Wait for 1 second between removals
except FloodWaitError as e:
print(f'Flood wait error, sleeping for {e.seconds} seconds')
time.sleep(e.seconds)
except Exception as e:
print(f'Failed to remove {member.first_name}: {e}')
async def main():
async with client:
await remove_all_members(channel_username)
if name == 'main':
import asyncio
asyncio.run(main())