简体   繁体   English

Telethon:留下聊天而不是频道请求

[英]Telethon: Leave a chat not a channel request

I am using the Telethon Telegram client library.我正在使用Telethon Telegram 客户端库。 I need to leave a Chat but there is only one request for leaving and that is LeaveChannelRequest .我需要离开Chat但只有一个离开请求,那就是LeaveChannelRequest
But as the name says, It is for Channels and not Chats .但顾名思义,它适用于Channels而不是Chats

Channels have both chat_id and access_hash but Chats only have chat_id . Channelschat_idaccess_hashChats只有chat_id

How can I leave a Chat ?我怎样才能离开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 ?我检查了tdlib库,它有一个东西叫CloseChat这似乎符合我需要什么,我如何在这里使用它telethon https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.CloseChat.html https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.CloseChat.html

You need to kick yourself with DeleteChatUserRequest :你需要用DeleteChatUserRequest踢自己:

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

You can also use dialog.delete() :您还可以使用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来改进上述内容:

client.delete_dialog(chat_id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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