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

Possible bug with event.get_pinned_message() #1458

Closed Dareten closed 4 years ago

Dareten commented 4 years ago

Checklist

Code that causes the issue

@client.on(events.ChatAction(chats=main_id))
async def normal_handler(event):
    global one, pin
    if event.new_pin:
        pin = await event.get_pinned_message()

Traceback

ERROR:telethon.client.updates:Unhandled exception on normal_handler
Traceback (most recent call last):
  File "D:\Python\lib\site-packages\telethon\client\updates.py", line 431, in _dispatch_update
    await callback(event)
  File "D:\Darts\hello.py", line 22, in normal_handler
    pin = await event.get_pinned_message()
  File "D:\Python\lib\site-packages\telethon\events\chataction.py", line 264, in get_pinned_message
    r = await self._client(functions.channels.GetMessagesRequest(
  File "D:\Python\lib\site-packages\telethon\client\users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "D:\Python\lib\site-packages\telethon\client\users.py", line 37, in _call
    await r.resolve(self, utils)
  File "D:\Python\lib\site-packages\telethon\tl\functions\channels.py", line 780, in resolve
    self.channel = utils.get_input_channel(await client.get_input_entity(self.channel))
  File "D:\Python\lib\site-packages\telethon\utils.py", line 263, in get_input_channel
    _raise_cast_fail(entity, 'InputChannel')
  File "D:\Python\lib\site-packages\telethon\utils.py", line 138, in _raise_cast_fail
    raise TypeError('Cannot cast {} to any kind of {}.'.format(
TypeError: Cannot cast InputPeerChat to any kind of InputChannel.

This bug was reproduced on my PC and heroku cloud, but on my friend's PC this code works well. It doesn't depend on the chat.

Lonami commented 4 years ago

This wasn't an issue before because small group chats did not properly handle pinned anyway, but since they now do a fix makes sense.