简体   繁体   English

C# TLSharp 删除用户聊天

[英]C# TLSharp delete user chat

How to delete chat user C# TLSharp?如何删除聊天用户 C# TLSharp? Error chat id错误聊天 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 );

If you are just testing to see how the user can be deleted, then this might help give you a better idea.如果您只是测试以查看如何删除用户,那么这可能会帮助您获得更好的主意。

I dont want to make any assumptions but this is one of the ways to delete the first participant from first chat.我不想做任何假设,但这是从第一次聊天中删除第一个参与者的方法之一。 I would recommend using Debugger to see how you can use Linq to filter out the chats and users that you are interested in removing.我建议使用 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);

View Sample code for looking up channels, participants, peers, chats etc from here查看用于从此处查找频道、参与者、同行、聊天等的示例代码

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

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