skip to Main Content

I’m working on a bot for supergroups.
How I can verify if member is admin?

my lib:org.telegram 4.2 https://core.telegram.org/bots/api

I tried with ChatMember, GetChatAdministrators and SendMessage methods but I have no idea how insert parameters because they don’t ask them but they have only .get option (null respose). Only GetChatAdministrators permit a .set method for ChatID but it give error

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

2

Answers


  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,
        };
    }
    

    Available methods
    source:
    https://core.telegram.org/bots/api#available-methods

    getChatAdministrators

    Use this method to get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.

    Login or Signup to reply.
  2. I had a same problem but I couldn’t find an answer from anywhere. Then I tried myself and finally today I found the following solution:

    public List<ChatMember> getChatAdministrators(Long chatId){
        List<ChatMember> chatAdministrators = Collections.emptyList();
        try {
            chatAdministrators = execute(new GetChatAdministrators(String.valueOf(chatId)));
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
        return chatAdministrators;
    }
    

    This method returns list of administrators of telegram groups, supergroups or channels.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search