-
Notifications
You must be signed in to change notification settings - Fork 380
how to get all members in channel? #461
Comments
You need a channel id and hash to get things done, here is a code sample: |
can u tell me whene i can get chanal hash? |
Sorry, I haven't written any vb.net code, but there must be online tools for code conversion. Here is simplified c# code you can use to get the hash:
|
ok thanks |
You'll also need to use offsets to get all the members, if a large group. Here's a snippet from one of my projects, though I like how @an2114 is getting the hash better, I'll probably use that :) public static async Task<ChannelInfo> GetChatInfo(string groupName)
{
if (! await AuthUser()) return null;
var result = new ChannelInfo();
var dialogs = (TLDialogs)await client.GetUserDialogsAsync();
var main = dialogs.chats.lists.Where(c => c.GetType() == typeof(TLChannel))
.Cast<TLChannel>()
.FirstOrDefault(c => c.title == (groupName));
var req = new TLRequestGetFullChannel()
{
channel = new TLInputChannel() { access_hash = main.access_hash.Value, channel_id = main.id }
};
var res = await client.SendRequestAsync<TeleSharp.TL.Messages.TLChatFull>(req);
//we have to do this in slices
var offset = 0;
result.Channel = main;
result.ChatFull = res;
while (offset < (res.full_chat as TLChannelFull).participants_count)
{
var pReq = new TLRequestGetParticipants()
{
channel = new TLInputChannel() { access_hash = main.access_hash.Value, channel_id = main.id },
filter = new TLChannelParticipantsRecent() { },
limit = 200,
offset = offset
};
var pRes = await client.SendRequestAsync<TLChannelParticipants>(pReq);
result.Users.AddRange(pRes.users.lists.Cast<TLUser>());
offset += 200;
await Task.Delay(500);
}
return result;
} Channelnfo() was just a quick class I made, modify as needed of course public class ChannelInfo
{
public TLChannel Channel { get; set; }
public TeleSharp.TL.Messages.TLChatFull ChatFull { get; set; }
public List<TLUser> Users { get; set; } = new List<TLUser>();
private DateTime _dateCreated;
public DateTime DateCreated
{
get { return _dateCreated; }
set
{
_dateCreated = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(Channel.date).ToLocalTime();
}
}
} |
I've error: "CHAT_ADMIN_REQUIRED" |
That happens because of a security configuration of a channel that means a user is not allowed to view the members. You can see the same behavior in different Telegram clients (e.g. a desktop or web app). |
Many times TLRequestGetParticipants return 1 more record. That's mean if I want to get 200 of 4200 contacts, many times get 201 contacts in result....!!! |
@hosseinGanjyar good catch! please propose a pull-request to fix it |
also where can i put these codes? |
We don't use github issues as a forum but to report bugs, so I'm closing this. If you want to have a more forum-like experience, you can ask questions in our gitter and telegram channels. |
It is blocking in this line forever |
how to get all members in channel?
The text was updated successfully, but these errors were encountered: