简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM