Search code examples
pythontelegram-bottelethon

BotMethodInvalidError occurs however i use a personal telegram account


I run this:

async def main():
    async for dialog in client.iter_dialogs():
        print(dialog.name, 'has ID', dialog.id)

if __name__ == '__main__':
    with client:
        client.loop.run_until_complete(main())

And it causes BotMethodInvalidError: The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot (caused by GetDialogsRequest). But i didn't use a bot, i used a personal telegram account.


Solution

  • Edit:

    if you're certain you used a personal account and no bot_token, this means there is garbage .session file from previous bot login.. change the name and login once again with phone number, the danya2.session will be the user session to use, danya seems to be a bot.

    TelegramClient('danya2', api_id=api_id_user, api_hash=api_hash_user)
    

    You can check the current account logged-in in client using client.get_me()


    Only users can get the open dialogs in the account, logins with bot token aren't allowed to do that through the Telegram api.

    a bot has to only handle realtime resources in events and cache them for future usage.