I'm attempting to set privacy rules for a Telegram account using Pyrogram.
In the below code I've tried to set ChatInvite privacy to Nobody but I got an error:
import asyncio
from pyrogram import Client, raw
async def main():
async with Client("authorization") as client:
await client.invoke(
raw.functions.account.SetPrivacy(
key=raw.types.PrivacyKeyChatInvite(),
rules=[raw.types.InputPrivacyValueDisallowAll()],
)
)
asyncio.run(main())
Here's the error I'm getting:
Traceback (most recent call last):
File "c:\Users\nimaxin\Desktop\app\main.py", line 16, in <module>
asyncio.run(main())
File "C:\Users\nimaxin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "C:\Users\nimaxin\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\nimaxin\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "c:\Users\nimaxin\Desktop\app\main.py", line 8, in main
await client.invoke(
File "C:\Users\nimaxin\Desktop\app\.venv\Lib\site-packages\pyrogram\methods\advanced\invoke.py", line 79, in invoke
r = await self.session.invoke(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\nimaxin\Desktop\app\.venv\Lib\site-packages\pyrogram\session\session.py", line 389, in invoke
return await self.send(query, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\nimaxin\Desktop\app\.venv\Lib\site-packages\pyrogram\session\session.py", line 357, in send
RPCError.raise_it(result, type(data))
File "C:\Users\nimaxin\Desktop\app\.venv\Lib\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
raise getattr(
pyrogram.errors.exceptions.bad_request_400.PrivacyKeyInvalid: Telegram says: [400 PRIVACY_KEY_INVALID] - The privacy key is invalid (caused by "account.SetPrivacy")
how can I correctly set the key and rules for this purpose?
Thanks to the help of some friends, I was able to find the solution to my question.
I should use pyrogram.raw.types.InputPrivacyKeyChatInvite
instead of pyrogram.raw.types.PrivacyKeyChatInvite