T
T
Turkmen Time2020-11-20 00:30:45
Python
Turkmen Time, 2020-11-20 00:30:45

How to make a script to remove all people from a channel in tg?

We need a script that will remove all people from the channel using a userbot.
I did this:

api_id = 'api'
api_hash = 'hash'
import time
from pyrogram.errors import FloodWait
from pyrogram import Client

chat = 'chat'

with Client("myacc", api_id, api_hash) as app:
    for u in app.get_chat_members(chat):
        with app:
            try:
                app.kick_chat_member(chat, u.id, int(time.time() + 60))
            except FloodWait as e:
                time.sleep(e.x)

but it gives an error:
raise ConnectionError("Client is already connected")
ConnectionError: Client is already connected

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-11-20
@MrSel

Need to remove extra line
with app:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question