LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.01k stars 1.41k forks source link

channels.DeleteHistoryRequest is incompatible with InputChannel #3867

Closed therapy closed 2 years ago

therapy commented 2 years ago

Code that causes the issue

channel = self._client(functions.channels.CreateChannelRequest(title='test', about=''))
channel_id = channel.to_dict()["chats"][0]["id"]
channel_hash = channel.to_dict()["chats"][0]["access_hash"]

self._channel = tl.types.InputChannel(channel_id, channel_hash)

self._client.send_message(self._channel, "test") # works fine
self._client(functions.channels.DeleteHistoryRequest(self._channel, max_id=0)) # error

Traceback

Traceback (most recent call last):
  File "*****", line 159, in <module>
    Telegram()
  File "*****", line 51, in __init__
    self._client(functions.channels.DeleteHistoryRequest(self._channel, max_id=0))
  File "C:\Users\*****\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Users\*****\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "C:\Users\*****\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 84, in _call
    result = await future
telethon.errors.rpcerrorlist.ChannelInvalidError: Invalid channel object. Make sure to pass the right types, for instance making sure that the request is designed for channels or otherwise look for a different one more suited (caused by DeleteHistoryRequest)
Lonami commented 2 years ago

You are using raw API, which means the results you are getting come directly from Telegram, and Telethon is not changing them in any way (other than adapting some input parameters where needed, all while respecting the intended values). Unfortunately this means it's something Telethon cannot "fix" and it's just the way Telegram's API works.

Lonami commented 2 years ago

For this particular case, I don't really know how the method works but I would recommend trying a different max_id (such as one from an existing message).