asdfg_rocks
asdfg_rocks

Reputation: 115

Telethon: Leave a chat not a channel request

I am using the Telethon Telegram client library. I need to leave a Chat but there is only one request for leaving and that is LeaveChannelRequest.
But as the name says, It is for Channels and not Chats.

Channels have both chat_id and access_hash but Chats only have chat_id.

How can I leave a Chat?

I have checked the tdlib library and it has a thing called CloseChat which seems to suit what I need, How can I use it here in telethon? https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.CloseChat.html

Upvotes: 2

Views: 3613

Answers (1)

Lonami
Lonami

Reputation: 7066

You need to kick yourself with DeleteChatUserRequest:

client(functions.messages.DeleteChatUserRequest(
    chat_id=chat_id,
    user_id='me'
))

You can also use dialog.delete():

for dialog in client.iter_dialogs():
    if dialog.id == chat_id:
        dialog.delete()

On more recent versions, the above can be improved by using client.delete_dialog instead:

client.delete_dialog(chat_id)

Upvotes: 4

Related Questions