Using the Telegram Bot API to Retrieve Chat Administrators

telegram bot api getchatadministrators
09 June 2025

How to Use the Telegram Bot API to Get Chat Administrators

Telegram bots are powerful tools for interacting with users and groups. One of the key features of these bots is the ability to manage users in groups and channels. By using the method getChatAdministrators in the Telegram Bot API, you can retrieve a list of currently active administrators of a chat (like a group or channel). This method allows you to obtain precise information about administrators, including user identifiers, usernames, and their status.

To start, you need to have a Telegram bot. If you haven't created your bot yet, you can refer to Telegram's documentation. After that, using your bot token, you can send API requests.

The method getChatAdministrators can be used as follows: first, you need to have the chat identifier (chat ID). This identifier can be in the form of a group number, a link to the group, or the username of the channel. Then, by sending a GET request to the specific address of this method, you can receive the information about the administrators.

Now let's get into the code section. Here’s an example of how to use this method with PHP. This code will help you retrieve the list of administrators for a group.

$token = "YOUR_BOT_TOKEN";
$chat_id = "YOUR_CHAT_ID";

$response = file_get_contents("https://api.telegram.org/bot" . $token . "/getChatAdministrators?chat_id=" . $chat_id);
$data = json_decode($response, true);

if ($data['ok']) {
foreach ($data['result'] as $administrator) {
echo "Username: " . $administrator['user']['username'] . "\n";
}
} else {
echo "Error fetching administrators";
}
?>

In this code:


1. $token = "YOUR_BOT_TOKEN";
In the first line, enter the bot token obtained from the BotFather bot.

2. $chat_id = "YOUR_CHAT_ID";
In this line, specify the identifier of the group or channel.

3. $response = file_get_contents(...);
In this line, the API request for retrieving the list of administrators is sent.

4. $data = json_decode($response, true);
Here, the JSON response is converted into a PHP array for easier access to its information.

5. if ($data['ok']) { ... }
This section checks whether the request was successful or not. If it was successful, the list of administrators will be provided, and each administrator's username will be displayed.

6. echo "Error fetching administrators";
If there's an error, a message indicating the failure will be displayed.

FAQ

?

How can I obtain the list of administrators of a group?

?

Can I get more information about the chat administrators?

?

Which programming languages can I use to work with the Telegram API?