dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
665 stars 155 forks source link

Error when clicking button #480

Closed serenity091 closed 1 year ago

serenity091 commented 1 year ago

Summary

_MissingSentinel' object has no attribute '_state' is the exception when attempting to click

Reproduction Steps

` try: await asyncio.sleep(0.3)

        await button.click()
        print("button clicked")

    except Exception as e:
        print("button not clicked")
        print(e)
        pass

`

Code

try:
            await asyncio.sleep(0.3)

            await button.click()
            print("button clicked")

        except Exception as e:
            print("button not clicked")
            print(e)
            pass

Expected Results

I am trying to click a button but it ends up not clicking. Previous versions of this library have done this without a problem.

Actual Results

Nothing happens.

System Information

Checklist

Additional Information

No response

dolfies commented 1 year ago

There's a good chance that the recent upstream pull broke something relating to this, but I cannot reproduce this (and it doesn't really seem possible looking at the code). Can you elaborate on how you are getting this error?

dakiba commented 1 year ago

I get a specific exception if I try to click a button:

Version: discord.py-self 2.0.0a2 Commit: 82b5f5d

code:

message = "......"
for comp in message.components:
    for child in comp.children:
        if child.label == "XXX":
            await child.click()
23-04-01 15:14:54 ERROR    discord.ext.tasks Unhandled exception in internal background task 'test'.
Traceback (most recent call last):
  File "/home/user/anaconda3/lib/python3.9/site-packages/discord/ext/tasks/__init__.py", line 239, in _loop
    await self.coro(*args, **kwargs)
  File "reload_module.py", line 38, in test
    await child.click()
  File "/home/user/anaconda3/lib/python3.9/site-packages/discord/components.py", line 228, in click
    message._state,
AttributeError: '_MissingSentinel' object has no attribute '_state'
dakiba commented 1 year ago

OK. Got a hotfix:

message = "......"
for comp in message.components:
    for child in comp.children:
        if child.label == "XXX":
            child.message = message
            await child.click()
dolfies commented 1 year ago

Should be fixed now. This is why I didn't immediately release after the upstream merge :)