skip to Main Content

I have looked through stack overflow and found what I need – export of removed (banned) users from specific telegram chat (supergroup).
the number of removed/banned users around 5000.

I did this:

channel_id = -########
users = client.get_participants(client.get_input_entity(channel_id))
for user in users:
    if user.deleted:
        print(user)

and this:

from telethon.tl.types import ChannelParticipantsKicked
from telethon.sync import TelegramClient

api_id = #########
api_hash = '################################'
group_id = '-##############'
client = TelegramClient('apptitle', api_id, api_hash)

async def main():
    await client.start()
    
    kicked_members = await client.get_participants(group_id, filter=ChannelParticipantsKicked)
    for member in kicked_members:
        print(TipyWolf, 502264640)

with client:
    client.loop.run_until_complete(main())

But what next? Where should I get a file? Where do I have to look at output of these actions?

I try to wait and looked at root folder and there is nothing really.
I’m expecting to get a file like csv or just massive of data so I could just copy it.

2

Answers


  1. Chosen as BEST ANSWER
    from telethon.tl.types import ChannelParticipantsKicked
    from telethon.sync import TelegramClient
    
    api_id = #
    api_hash = '#'
    group_id = '-#'
    client = TelegramClient('apptitle', api_id, api_hash)
    
    async def main():
       await client.start() 
       kicked_members = await client.get_participants(group_id, filter=ChannelParticipantsKicked)
       file_name = 'kicked_members.txt'
       with open(file_name, 'w') as file:
           for member in kicked_members:
           file.write(member + 'n')
    

    I run a find option in windows explorer to find a file kicked_members.txt but it found nothing :( What did i do wrong ?


  2. No. Your code does not give you a file. And I cannot understand why that code wants to print TipyWolf a few thousand times.

    . . .
       kicked_members = await client.get_participants(group_id, filter=ChannelParticipantsKicked)
    
       # Define the file name
       file_name = 'kicked_members.txt'
       # Open the file in write mode ('w')
       with open(file_name, 'w') as file:
           for member in kicked_members:
           file.write(member + 'n')
    

    I assumed member is a string holding usernames, adjust the file.write() if its not. The file would be in the same directory of the python file.

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