问题
I am writing a C# desktop app.in this app I write a telegram Id of a user and it says that user is member of the channel or not. my bot is admin of the channel.
I use telegram.bot v9 nugget and searched about this issue all day.
I tried using GetChatMembersCountAsync() in v13 and a lot of other methods but didn't work.
static private Api bot = new Api("Token");
long id;
string channel="@ChannelName";
public Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
id = long.Parse(textBox7.Text);
if (IsMember(id,channel))
MessageBox.Show("This user is member of channel");
else
MessageBox.Show("This user is not a member of channel");
}
private bool IsMember(long id,string channelName)
{
//??????????????
}
Is there a method for a telegram bot access to list of members of a channel? what should I write in the IsMember() method?
Thank you very much
This problem solved by updating telegram.bot nugget to v10 and using GetChatMemberAsync method.
private bool IsMember(long id,string channelName)
{
var t = bot.GetChatMemberAsync(channelName, id);
if (t.Result.Status.ToString().Length > 25)
return false;
return true;
}
thank you
回答1:
You can use getChatMember method to do that, see following example.
回答2:
Regarding to Telegram Bot API documentation currently there is no method available for bots to get a list of chat members (channel or group).
Here is a small trick:
You can check the updates (messages) came from Telegram to your webhook, if new_chat_members
field has a value and the chat_id
field indicates that it's from your channel, then you may save the information about the recent users who joined your channel.
来源:https://stackoverflow.com/questions/46542451/how-do-i-know-if-a-telegram-user-joined-my-channel