skip to Main Content

Basically I have a group(of which I am admin) in which I want to be able to add and kick-out user programmatically. I created a telegram app using my telegram account. I wanted to access the method channels.EditBanned. The group was created using same account that was used to create app. This one:

new Api.channels.EditBanned({
  channel: "Test_Channel",
  participant: "vishalkale151071",
  bannedRights: new Api.ChatBannedRights({
    untilDate: 43,
    viewMessages: 0,
    sendMessages: 1,
    sendMedia: true,
    sendStickers: true,
    sendGifs: false,
    sendGames: true,
    sendInline: true,
    sendPolls: true,
    changeInfo: true,
    inviteUsers: true,
    pinMessages: true,
  }),
})
); 

But got error :

RPCError: 403: CHAT_WRITE_FORBIDDEN (caused by channels.EditBanned)

Reference : https://gram.js.org/tl/channels/EditBanned

2

Answers


  1. to ban/kick someone you can use:

    new Api.channels.EditBanned({
          channel: new Api.InputChannel({
            channelId: <channel_id>,
            accessHash: BigInt(<hash>),
          }),
          participant: <user_id>,
          bannedRights: new Api.ChatBannedRights({
            untilDate: 43,
            viewMessages: true,
            sendMessages: true,
            sendMedia: true,
            sendStickers: true,
            sendGifs: true,
            sendGames: true,
            sendInline: true,
            sendPolls: true,
            changeInfo: true,
            inviteUsers: true,
            pinMessages: true,
          }),
        })
    

    to get the channel accessHash and id, you must store the result when you call the createChannel:

    const result = await client.invoke(
        new Api.channels.CreateChannel({
          title: "grupo-legal-2",
          about: "about test",
          broadcast: true,
          // megagroup: true,
          // forImport: true,
          geoPoint: new Api.InputGeoPoint({
            lat: -26.30444,
            long: -48.84556,
            accuracyRadius: 100,
          }),
          address: "address test",
        })
      );
    
      console.log(result);
      console.log(result.chats[0].id);
      console.log(result.chats[0].accessHash);
    
    Login or Signup to reply.
  2. Ok . Since I had a deadline for the project , I ended up achieving the delete functionality by creating a bot and invoking bot.banMember method . For this to work one need to add the bot to the telegram group with admin privileges . also I feel its much simpler this way . Apart from directly messaging users in telegram , you can pretty much do everything . –

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