【问题标题】:How verify if a member is admin?如何验证成员是否为管理员?
【发布时间】:2019-10-23 15:37:18
【问题描述】:

我正在为超级组开发一个机器人。 如何验证成员是否为管理员?

我的 lib:org.telegram 4.2 https://core.telegram.org/bots/api

我尝试使用 ChatMember、GetChatAdministrators 和 SendMessage 方法,但我不知道如何插入参数,因为它们不询问它们,但它们只有 .get 选项(空响应)。只有 GetChatAdministrators 允许 ChatID 使用 .set 方法,但它会报错

GetChatAdministrators getadmin = new GetChatAdministrators().setChatId(ChatIDSupergroup);
            ArrayList<ChatMember> s = null;
            try {
                s = getadmin.deserializeResponse(null); //Unable to deserialize response
            } catch (TelegramApiRequestException e) {
                e.printStackTrace();
            }
ChatMember member = new ChatMember(); //There are only get options
String status=member.getStatus(); //null

【问题讨论】:

    标签: java telegram telegram-bot


    【解决方案1】:
        function adminCheck( id, chat_id ) {
        var bAdminCheck = false;
        var name = "";
        var aChatMember = getChatAdministrators( chat_id );
        var contents = JSON.parse( aChatMember );
        var i = 0;
        while( !bAdminCheck && ( i < contents.result.length ) ) {
            if( id == contents.result[i].user.id ) {
                bAdminCheck = true;  
            }
            i++;
        }  
        return {
        AdminCheck: bAdminCheck,
        };
    }
    

    可用方法 资源: https://core.telegram.org/bots/api#available-methods

    getChatAdministrators

    使用此方法获取聊天中的管理员列表。成功时,返回一个 ChatMember 对象数组,其中包含有关除其他机器人之外的所有聊天管理员的信息。如果聊天是群组或超级群组,并且没有指定管理员,则只会返回创建者。

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 2015-01-22
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 2020-02-05
      相关资源
      最近更新 更多