Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'id' #21

Closed
Athirst1998 opened this issue Feb 19, 2023 · 12 comments
Closed

AttributeError: 'NoneType' object has no attribute 'id' #21

Athirst1998 opened this issue Feb 19, 2023 · 12 comments

Comments

@Athirst1998
Copy link

from pyromod import listen
from pyromod.listen.listen import ListenerTimeout

@app.on_message()
async def test(_, message):
    print(message)
    
 
app.run()

when I send a message to channel , the bot raise this error:

'NoneType' object has no attribute 'id'
Traceback (most recent call last):
File ".....venv/lib/python3.10/site-packages/pyrogram/dispatcher.py", line 226, in handler_worker
if await handler.check(self.client, parsed_update):
File "......venv/lib/python3.10/site-packages/pyromod/listen/listen.py", line 196, in check
(message.chat.id, message.from_user.id, message.id),
AttributeError: 'NoneType' object has no attribute 'id'

how can I fix error?

Athirst1998 added a commit to Athirst1998/pyromod that referenced this issue Feb 19, 2023
@TAMILVIP007
Copy link

@Athirst1998 The code and error are no where related tho

@AbirHasan2005
Copy link

I got same error:

pyrogram.dispatcher - ERROR - 'NoneType' object has no attribute 'id'
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pyrogram/dispatcher.py", line 226, in handler_worker
    if await handler.check(self.client, parsed_update):
  File "/usr/local/lib/python3.8/dist-packages/pyromod/listen/listen.py", line 196, in check
    (message.chat.id, message.from_user.id, message.id),
AttributeError: 'NoneType' object has no attribute 'id'

it's latest version from pypi

@Surendra9123
Copy link

@AbirHasan2005 try message.sender_chat.id

@Surendra9123
Copy link

@AbirHasan2005 https://t.me/pyrogramchat/535246 look here..

@IronGiu
Copy link

IronGiu commented Apr 4, 2023

Same error, in same file listen.py happen if a group/supergroup or channel start a live broadcast (video call, group call or whatever you want to call it)!
Without pyromod no error raised during group call.
To reproduce it, just include pyromod and start a group call in a group where your bot is (normal bot, not userbot)

Add:
The pull request #22 fix the problem even for the group call error.

@canwushuang
Copy link

canwushuang commented May 23, 2023

From tg “My problem is solved
I added this code to the part where the pyromod gets an error
if message.from_user is None:
_id = message.sender_chat.id
else:
_id = message.from_user.id
And finally, instead of the previous parameter, I put _id”

pyromod/listen/listen.py

@patchable
    async def check(self, client, message):
        if message.from_user is None:
            _id = message.sender_chat.id
        else:
            _id = message.from_user.id
        listener = client.match_listener(
            (message.chat.id, _id, message.id),
            ListenerTypes.MESSAGE,
        )[0]

        listener_does_match = handler_does_match = False

@catty-dev
Copy link

catty-dev commented May 25, 2023

i got the same error in my code only when I import pyromod. With parogram alone it runs fine. Pls fix the bug

@EDM115
Copy link

EDM115 commented Aug 29, 2023

using v2.0.0, and constantly get the same error :

2023-08-29 12:15:22,881 - ERROR - pyrogram.dispatcher - MainThread - 'NoneType' object has no attribute 'id'
Traceback (most recent call last):
  File "/venv/lib/python3.11/site-packages/pyrogram/dispatcher.py", line 226, in handler_worker
    if await handler.check(self.client, parsed_update):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.11/site-packages/pyromod/listen/listen.py", line 196, in check
    (message.chat.id, message.from_user.id, message.id),
                      ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'id'

@Sunda001
Copy link

@EDM115 Umm

@IronGiu
Copy link

IronGiu commented Aug 29, 2023

using v2.0.0, and constantly get the same error :


2023-08-29 12:15:22,881 - ERROR - pyrogram.dispatcher - MainThread - 'NoneType' object has no attribute 'id'

Traceback (most recent call last):

  File "/venv/lib/python3.11/site-packages/pyrogram/dispatcher.py", line 226, in handler_worker

    if await handler.check(self.client, parsed_update):

       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/venv/lib/python3.11/site-packages/pyromod/listen/listen.py", line 196, in check

    (message.chat.id, message.from_user.id, message.id),

                      ^^^^^^^^^^^^^^^^^^^^

AttributeError: 'NoneType' object has no attribute 'id'

I modified pyromod and fixed this error long time ago, this error happen because not all updates have chat.id or from_user.id or a message id, but pyromod use these on every request, for example if an update came from a channel or from live broadcast update of a group/channel etc message.from_user.id is not present at all! Not even as "None".

If you implement the code of the pull request #22 problem disappear and all work great even after many tests.

I hope that will be implemented asap!

@SpidyBoYz
Copy link

I am also getting the same error:

'NoneType' object has no attribute 'id'
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.11/site-packages/pyrogram/dispatcher.py", line 226, in handler_worker
    if await handler.check(self.client, parsed_update):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.heroku/python/lib/python3.11/site-packages/pyromod/listen/listen.py", line 196, in check
    (message.chat.id, message.from_user.id, message.id),
                      ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'id'

Using the latest version (i.e. 2.0.0) from pypi

@usernein
Copy link
Owner

usernein commented Sep 3, 2023

#30 fixes this!
Thank you for reporting and contributing!

@usernein usernein closed this as completed Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests