getChatAdministrators
Returns: ChatMember[]Official docs ↗
Use this method to get a list of administrators in a chat, which aren't bots. Returns an Array of ChatMember objects.
Parameters
chat_idIntegerStringRequiredUnique identifier for the target chat or username of the target supergroup or channel (in the format
@channelusername)Returns
On success, an array of ChatMember objects is returned.
GramIO Usage
ts
// List all human administrators in the current chat
bot.command("admins", async (ctx) => {
const admins = await bot.api.getChatAdministrators({
chat_id: ctx.chat.id,
});
const names = admins.map((a) => a.user.first_name).join(", ");
await ctx.send(`Administrators: ${names}`);
});ts
// Check if a specific user is an admin
async function isAdmin(chatId: number | string, userId: number) {
const admins = await bot.api.getChatAdministrators({ chat_id: chatId });
return admins.some((a) => a.user.id === userId);
}ts
// Verify whether the bot itself has admin rights
bot.command("amiadmin", async (ctx) => {
const me = await bot.api.getMe();
const admins = await bot.api.getChatAdministrators({
chat_id: ctx.chat.id,
});
const isBotAdmin = admins.some((a) => a.user.id === me.id);
await ctx.send(isBotAdmin ? "I am an admin!" : "I am not an admin.");
});ts
// Direct API call for a public channel by username
const admins = await bot.api.getChatAdministrators({
chat_id: "@durov",
});
console.log(`${admins.length} admin(s) found`);Errors
| Code | Error | Cause |
|---|---|---|
| 400 | Bad Request: chat not found | Invalid or inaccessible chat_id — verify the chat ID and ensure the bot is a member |
| 400 | Bad Request: method is available for supergroup and channel chats only | Called on a private chat or basic group — only works on supergroups and channels |
| 403 | Forbidden: bot is not a member of the channel chat | Bot was removed from the chat or never joined |
| 429 | Too Many Requests: retry after N | Rate limit hit — check retry_after, use the auto-retry plugin |
TIP
Use GramIO's auto-retry plugin to handle 429 errors automatically.
Tips & Gotchas
- Bots are excluded from the results. The method returns only human administrators. To check if the bot itself has admin rights, call
getMe()and compare the bot's ID against the returned list. - Works on supergroups and channels only. Calling this on a private chat or a basic group raises an error. Always check the chat type first.
- Results may be cached briefly. Telegram may serve a slightly stale admin list; don't rely on it for instant permission checks after a promotion.
- The creator has
status: "creator". Other admins havestatus: "administrator". Filter by status to distinguish the owner from regular admins. @usernamestrings work for public chats. Pass"@channelusername"for public supergroups and channels — no need to look up the numeric ID.- Custom titles are available. For
ChatMemberAdministrator, thecustom_titlefield shows the admin's display title if one was set.
See Also
- getChatMember — get info about a specific member
- promoteChatMember — grant or revoke admin rights
- getChatMemberCount — total member count
- getChat — get general chat info
- ChatMember — the returned union type