1

I want that some one can add my bot to his channel. For that I want to save the webhook (chat.id) of the channel in a database.

My code:

async with bot.conversation(chat.id) as conv:
        await conv.send_message("Which channel you want add? (invite link of the channel):")
        resp = await conv.get_response()
        hookName = resp.message

        hook = await bot.get_entity(hookName)
        print(hook)
        print(hook.chat_id)
        print(hook.user_id)

I get this error at the line with get_entity when I use the invite link:

telethon.errors.rpcerrorlist.BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by CheckChatInviteRequest)

And this error when I use the channelname:

ValueError: No user has "channelname" as username

Im wondering why it works when I hardcode the channel name but not as an response...

Would be nice if a user could just enter the chat name or channel name or the invite links and I get the id from that.

Is there any way to do that?

Thanks :)

MaTok
  • 353
  • 3
  • 16
  • Use `client.get_peer_id`, it will use cache (resolving usernames is expensive) and should extract the ID from invite links without making requests. – Lonami Jan 10 '21 at 11:29
  • Thank you perfect! Is there any possibility to have a real unique identifier? E. g. when I add "Testroom" I dont get my channel (ofcause there are many with this name cause its not unipe)... and when I try to use the invite link I get this error: ```AttributeError: 'str' object has no attribute 'SUBCLASS_OF_ID'``` – MaTok Jan 10 '21 at 18:57
  • Chat names are unreliable. Usernames are loaded from cache. Invite links should always work. If you believe it's a bug open a report in the GitHub repository with *clear* reproduction steps. – Lonami Jan 11 '21 at 18:49
  • Are you sure that the invite link should work? On public groups I dont have this issue – MaTok Jan 12 '21 at 17:21
  • They *should*, but if they don't it might be a bug. – Lonami Jan 12 '21 at 17:46

0 Answers0