voidbar / forwardgram

Forward messages from multiple Telegram channels to one of your own!
154 stars 183 forks source link

AttributeError: 'Chat' object has no attribute 'access_hash' #16

Open siddAhmed opened 4 years ago

siddAhmed commented 4 years ago

I have done everything correctly (i guess) but every time it throws this error. Any clue what's wrong?

The console throws this error :


  File "forwardgram.py", line 49, in <module>
    start(config)
  File "forwardgram.py", line 24, in start
    output_channel_entities.append(InputChannel(d.entity.id, d.entity.access_hash))
AttributeError: 'Chat' object has no attribute 'access_hash'
ekkutlu commented 4 years ago

Hi, Can you find any solution about this error?

ekkutlu commented 4 years ago

Any solution??

voidbar commented 4 years ago

Juat update your python version and make sure you have the chats and proper permissions accessing them.

On Thu, 25 Jun 2020 at 15:18 ekkutlu notifications@github.com wrote:

Any solution??

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/voidbar/forwardgram/issues/16#issuecomment-649505908, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGKY5UUGGTE6R5BCLC3WEKTRYM6BZANCNFSM4L3L6E7A .

Bee53Apps commented 4 years ago

I have done everything correctly (i guess) but every time it throws this error. Any clue what's wrong?

The console throws this error :

  File "forwardgram.py", line 49, in <module>
    start(config)
  File "forwardgram.py", line 24, in start
    output_channel_entities.append(InputChannel(d.entity.id, d.entity.access_hash))
AttributeError: 'Chat' object has no attribute 'access_hash'

I also ran into this problem. It seemed to be caused mostly when trying to forward from a group chat instead of an actual channel even though the distinction is not always apparent in Telegram. (I think) only channels have an access_hash, hence the error (at least that was the case for me).

I found initially running something like:

for d in client.iter_dialogs():
        print(d.name + ": " + str(d.entity.id)

outputs the shorter id codes for all channels and chats on your Telegram account which can then be used to build your input and output channel entity lists using the simpler and less error-prone: output_channel_entities.append(12345678) where 12345678 was the short id codes from above.

Optionally - If you change any code in and around the event handler and hit further issues sending to a chat vs channel, then inside the handler you can check:

if isinstance(event.to_id, PeerChannel): #check if channel or chat (they may need to be handled differently)
    print("do something with channel")
elif isinstance(event.to_id, PeerChat):
    print("do something with chat")
else:
    print("if you reach here, give up and go grab beer!")

I'm still learning Python so I'm sure there will be better ways but this is what worked for me when trying to handle both Chats and Channels.

liyoungc commented 3 years ago

I've used @Bee53Apps 's method and succeeded, just need to mention you need to create a bot and make the bot the admin of the target channel in order to forward something there. Also it's wired that it is constantly showing:

2021-05-15 02:22:17,241 - root - INFO - Listening on 1 channels. Forwarding messages to 2 channels

And the forwarded msg repeated itself for twice? Anyone has some idea? Thanks in advance.

pidori-ne-poluchat-parol commented 10 months ago

so how to solve this problem?