簡體   English   中英

C# TLSharp 刪除用戶聊天

[英]C# TLSharp delete user chat

如何刪除聊天用戶 C# TLSharp? 錯誤聊天 ID

var dialogs = await client.GetUserDialogsAsync(limit: 50) as TLDialogs;
var dialog = (dialogs.Dialogs[0]) as TLDialog;
var id= (dialog.Peer as TLPeerUser).UserId;
var deleteRequest = new TLRequestDeleteChatUser()
{  
   UserId = new TLInputUser() {
         UserId = id
   }
};
await client.SendRequestAsync<TLUpdates>(deleteRequest );

如果您只是測試以查看如何刪除用戶,那么這可能會幫助您獲得更好的主意。

我不想做任何假設,但這是從第一次聊天中刪除第一個參與者的方法之一。 我建議使用 Debugger 來查看如何使用 Linq 過濾掉您有興趣刪除的聊天和用戶。

    var dialogs = (TLDialogs)await client.GetUserDialogsAsync(limit: 50);

    TLChat chat = dialogs.Chats.OfType<TLChat>().FirstOrDefault();
    int userId = 0; // User ID To Delete

    var request = new TLRequestGetFullChat() { ChatId = chat.Id };
    var fullChat = await client.SendRequestAsync<TeleSharp.TL.Messages.TLChatFull>(request);

    var participants = (fullChat.FullChat as TeleSharp.TL.TLChatFull).Participants as TLChatParticipants;
    var p = participants.Participants.FirstOrDefault();

    if (p is TLChatParticipant)
    {
        var participant = p as TLChatParticipant;
        Console.WriteLine($"\t{participant.UserId}");
        userId = participant.UserId;
    }
    else if (p is TLChatParticipantAdmin)
    {
        var participant = p as TLChatParticipantAdmin;
        Console.WriteLine($"\t{participant.UserId}**");
        userId = participant.UserId;
    }
    else if (p is TLChatParticipantCreator)
    {
        var participant = p as TLChatParticipantCreator;
        Console.WriteLine($"\t{participant.UserId}**");
        userId = participant.UserId;
    }

    var deleteRequest = new TLRequestDeleteChatUser()
    {
        ChatId = chat.Id,
        UserId = new TLInputUser()
        {
            UserId = userId
        }
    };
    await client.SendRequestAsync<TLUpdates>(deleteRequest);

查看用於從此處查找頻道、參與者、同行、聊天等的示例代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM