usernein / pyromod

A monkeypatcher add-on for Pyrogram
https://pyromod.pauxis.dev/
GNU Lesser General Public License v3.0
223 stars 70 forks source link

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

Closed Athirst1998 closed 1 year ago

Athirst1998 commented 1 year ago
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?

TAMILVIP007 commented 1 year ago

@Athirst1998 The code and error are no where related tho

AbirHasan2005 commented 1 year ago

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 commented 1 year ago

@AbirHasan2005 try message.sender_chat.id

Surendra9123 commented 1 year ago

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

IronGiu commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

EDM115 commented 1 year ago

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 commented 1 year ago

@EDM115 Umm

IronGiu commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

30 fixes this!

Thank you for reporting and contributing!