to ask for help with python and/or executing this script, join discord: https://discord.gg/zpu7YUP3Um
There's not telegram API method for this, we need to call MTProto methods to retrieve messages from the "Recent Actions" (Admin Log) since deleted messages (and medias) gets moved there for 48 hours before the permanent deletion.
from telethon import TelegramClient, events, sync
from telethon.tl.types import InputChannel, PeerChannel
from telethon.tl.types import Channel
import time
# Get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
# or from https://tjhorner.dev/webogram/#/login
api_id = API_ID
api_hash = API_HASH
client = TelegramClient('session_name', api_id, api_hash)
client.start()
group = client.get_entity(PeerChannel(GROUP_CHAT_ID))
#messages = client.get_admin_log(group)
file1 = open("dump.json","w")
c = 0
m = 0
for event in client.iter_admin_log(group):
if event.deleted_message:
print("Dumping message",c, "(", event.old.id, event.old.date,")")
file1.write(event.old.to_json() + ",")
c+=1
if event.old.media:
m+=1
#print(event.old.media.to_dict()['Document']['id'])
client.download_media(event.old.media, str(event.old.id))
print(" Dumped media", m)
time.sleep(0.1)
How do I run this?
Please check https://docs.python.org/3/faq/
Hi guys
I have
api_id = **
api_hash = **
group_id = **
But when I run
c:\1>python backup_script.py
I have
Please enter your phone (or bot token): ****
Traceback (most recent call last):
File "c:\1\backup_script.py", line 13, in
client.start()
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\client\auth.py", line 128, in start
else self.loop.run_until_complete(coro)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 684, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\client\auth.py", line 184, in _start
await self.send_code_request(phone, force_sms=force_sms)
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\client\auth.py", line 434, in send_code_request
result = await self(functions.auth.SendCodeRequest(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\client\users.py", line 30, in call
return await self._call(self._sender, request, ordered=ordered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\client\users.py", line 67, in _call
future = sender.send(request, ordered=ordered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\network\mtprotosender.py", line 183, in send
state = RequestState(request)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\network\requeststate.py", line 17, in init
self.data = bytes(request)
^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\tl\tlobject.py", line 194, in bytes
return self._bytes()
^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\tl\functions\auth.py", line 643, in _bytes
self.serialize_bytes(self.api_hash),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hunny\AppData\Local\Programs\Python\Python312\Lib\site-packages\telethon\tl\tlobject.py", line 112, in serialize_bytes
raise TypeError(
TypeError: bytes or str expected, not <class 'int'>
Any help, please