简体   繁体   English

我如何知道电报用户是否加入了我的频道?

[英]How do I know if a telegram user joined my channel?

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. 我正在编写一个C#桌面应用程序。在此应用程序中,我编写了一个用户的电报ID,并说该用户是否是该频道的成员。 my bot is admin of the channel. 我的机器人是该频道的管理员。

I use telegram.bot v9 nugget and searched about this issue all day. 我使用telegram.bot v9块,并整日搜索了此问题。

I tried using GetChatMembersCountAsync() in v13 and a lot of other methods but didn't work. 我尝试在v13中使用GetChatMembersCountAsync()和许多其他方法,但是没有用。

    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? 我应该在IsMember()方法中写些什么?

Thank you very much 非常感谢你


This problem solved by updating telegram.bot nugget to v10 and using GetChatMemberAsync method. 通过将telegram.bot块更新到v10并使用GetChatMemberAsync方法可以解决此问题。

    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 谢谢

You can use getChatMember method to do that, see following example. 您可以使用getChatMember方法执行此操作,请参见以下示例。

很棒的电报机器人

Regarding to Telegram Bot API documentation currently there is no method available for bots to get a list of chat members (channel or group). 关于Telegram Bot API文档,目前尚无方法可用于漫游器获取聊天成员(频道或群组)列表。 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. 这是一个小技巧:您可以检查来自Telegram到new_chat_members的更新(消息),如果new_chat_members字段具有值,并且chat_id字段指示该消息来自您的频道,则可以保存有关最近加入的用户的信息您的频道。

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

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