await self.client.kick_participant(entity=chat_id,
File "/home/tgcleaning/TGCleaner/virtualenv/lib/python3.11/site-packages/telethon/client/chats.py", line 1171, in kick_participant
resp = await self(functions.channels.EditBannedRequest(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tgcleaning/TGCleaner/virtualenv/lib/python3.11/site-packages/telethon/client/users.py", line 30, in __call__
return await self._call(self._sender, request, ordered=ordered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tgcleaning/TGCleaner/virtualenv/lib/python3.11/site-packages/telethon/client/users.py", line 87, in _call
result = await future
^^^^^^^^^^^^
telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by EditBannedRequest)
Why it raises ChatWriteForbiddenError when i'm trying to kick user?
Debug it hard enough. start by confirming get_entity(chat_id).left isn't True
Are you the chat admin?
ChatAdminRequiredError not raised
Well, more fundamentally, non admins cannot ban, mute or restrict permissions of another user of the chat (provided they're both members of the chat). So even if no error is raised, you cannot do admin actions. But I guess that is likely not your issue. Right?
When i was not admin, it raised ChatAdminRequiredError, but not now
Do you have permissions to ban users? Is this your own test chat with your own accounts or is it some group that you were promoted to admin in?
Probably im not in chat, but should be there another exception?
Ok for me attempting to ban a user in a chat where I am not an admin gives the following error, I'll try the other thing too telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by EditBannedRequest)
Now I did it for a person in a chat where I am not even there, and I get the same error
ChatAdminRequired applies to chats you have joined
So, Case 1: I and the other user is in the same chat. I am not an admin. I get the ChatAdminRequiredError. Case 2: I am not in the chat where the other user is. I am not an admin (obviously). I still get the ChatAdminRequiredError. How?
pics or it didn't happen for the one you didn't join, print(get_entity(chat_id).left) followed by its error
AAAAH my bad. For case 2, I checked channel instead of the associated chat for that one. I got this error instead telethon.errors.rpcerrorlist.ChatWriteForbiddenError: You can't write in this chat (caused by EditBannedRequest)
And is it valid exception for this case? I think - no
Обсуждают сегодня