GramJS

channels.EditAdmin

Modify the admin rights of a user in a supergroup/channel.

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.channels.EditAdmin({
      channel: "username",
      userId: "username",
      adminRights: new Api.ChatAdminRights({
        changeInfo: true,
        postMessages: true,
        editMessages: true,
        deleteMessages: true,
        banUsers: true,
        inviteUsers: true,
        pinMessages: true,
        addAdmins: true,
        anonymous: true,
        manageCall: true,
        other: true,
      }),
      rank: "some string here",
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.Updates = await client.invoke(
    new Api.channels.EditAdmin({
      channel: "username",
      userId: "username",
      adminRights: new Api.ChatAdminRights({
        changeInfo: true,
        postMessages: true,
        editMessages: true,
        deleteMessages: true,
        banUsers: true,
        inviteUsers: true,
        pinMessages: true,
        addAdmins: true,
        anonymous: true,
        manageCall: true,
        other: true,
      }),
      rank: "some string here",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
channelInputChannelThe supergroup/channel.
userIdInputUserThe ID of the user whose admin rights should be modified
adminRightsChatAdminRightsThe admin rights
rankstringIndicates the role (rank) of the admin in the group: just an arbitrary string

Result

Updates

Possible errors

CodeTypeDescription
400ADMINS_TOO_MUCHThere are too many admins
400BOTS_TOO_MUCHThere are too many bots in this chat/channel
400BOT_CHANNELS_NABots can't edit admin privileges
400BOT_GROUPS_BLOCKEDThis bot can't be added to groups
400CHANNEL_INVALIDThe provided channel is invalid
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup
403CHAT_ADMIN_INVITE_REQUIREDYou do not have the rights to do this
400CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this
403CHAT_WRITE_FORBIDDENYou can't write in this chat
406FRESH_CHANGE_ADMINS_FORBIDDENYou were just elected admin, you can't add or modify other admins yet
400INPUT_USER_DEACTIVATEDThe specified user was deleted
400PEER_ID_INVALIDThe provided peer id is invalid
403RIGHT_FORBIDDENYour admin rights do not allow you to do this
400USERS_TOO_MUCHThe maximum number of users has been exceeded (to create a chat, for example)
400USER_BLOCKEDUser blocked
403USER_CHANNELS_TOO_MUCHOne of the users you tried to add is already in too many channels/supergroups
400USER_CREATORYou can't leave this channel, because you're its creator
400USER_ID_INVALIDThe provided user ID is invalid
400USER_NOT_MUTUAL_CONTACTThe provided user is not a mutual contact
403USER_PRIVACY_RESTRICTEDThe user's privacy settings do not allow you to do this
403USER_RESTRICTEDYou're spamreported, you can't create channels or chats.

Can bots use this method?

Yes

Channels

How to handle channels, supergroups, groups, and what's the difference between them.