skip to Main Content

With telethon you can do pretty much anything you want around Telegram. However, I cannot find a way to get a list of removed (banned) users in a group/channel. Any ideas?

For the record, you can do that via Telegram’s GUI by going to Edit > Permissions > Removed Users.

2

Answers


  1. In order to get a list of all the removed users in a Telegram group/channel using Telethon you need to use get_participants() with filter parameter set to ChannelParticipantsKicked.

    from telethon.tl.types import ChannelParticipantsKicked # import type to use as filter
    kicked_members = await client.get_participants(chat, filter=ChannelParticipantsKicked)
    

    If you’d prefer to loop over the result without assign it to a variable you can use iter_participants() instead.

    from telethon.tl.types import ChannelParticipantsKicked 
    async for user in client.iter_participants(chat, filter=ChannelParticipantsKicked):
        print(user.first_name)
    

    NR: here is a list of all the avaible filters usable with get/iter_participants().

    Login or Signup to reply.
  2. @client.on(events.NewMessage(pattern="/[Bb]anlist",from_users=admin))
    async def banlist(event):
      text = (event.raw_text).split(" ")
      try:
        bans = await  client.get_participants(text[1] , filter=ChannelParticipantsKicked)
        ban_list = ""
        for i in bans:
          if (i.username != None):
            ban_list += "@" + i.username +'n'
        await event.reply("BAN LSIT: {}".format(ban_list))
      except:
        await event.reply("ERROR!")
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search