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/
i keep getting this error can someone help me pls
Traceback (most recent call last):
File "C:\Users\RoGo\Desktop\backup_script.py", line 13, in
client.start()
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\client\auth.py", line 133, in start
else self.loop.run_until_complete(coro)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1520.0_x64__qbz5n2kfra8p0\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\client\auth.py", line 189, in _start
await self.send_code_request(phone, force_sms=force_sms)
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\client\auth.py", line 514, in send_code_request
result = await self(functions.auth.SendCodeRequest(
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\client\users.py", line 30, in call
return await self._call(self._sender, request, ordered=ordered)
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\client\users.py", line 58, in _call
future = sender.send(request, ordered=ordered)
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\network\mtprotosender.py", line 176, in send
state = RequestState(request)
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\network\requeststate.py", line 17, in init
self.data = bytes(request)
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\tl\tlobject.py", line 194, in bytes
return self._bytes()
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\tl\functions\auth.py", line 488, in _bytes
self.serialize_bytes(self.api_hash),
File "C:\Users\RoGo\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\telethon\tl\tlobject.py", line 112, in serialize_bytes
raise TypeError(
TypeError: bytes or str expected, not <class 'int'>