如何验证成员是否为管理员?

时间:2019-06-08 11:40:18

标签: java telegram telegram-bot

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

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

我尝试使用ChatMember,GetChatAdministrators和SendMessage方法,但是我不知道如何插入参数,因为它们不询问它们,而只有.get选项(null respose)。只有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

1 个答案:

答案 0 :(得分:0)

    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对象数组,其中包含有关除其他漫游器以外的所有聊天管理员的信息。如果聊天是群组或超级群组,并且没有任命管理员,则只会返回创建者。

相关问题