discord-py-ui / discord-ui

A discord.py extension for sending, receiving and handling ui interactions in discord
https://discord-ui.rtfd.io/
MIT License
36 stars 9 forks source link

AttributeError when creating extension instance inside custom Bot class #85

Closed Mabi19 closed 2 years ago

Mabi19 commented 2 years ago

When creating the extension as part of a custom bot class, you get an AttributeError. I'm using Python 3.9.6, discord.py version 1.7.3 and discord-ui version 3.1.0.

Traceback (most recent call last):
  File "main.py", line 10, in <module>
    bot = CustomBot(command_prefix="!")
  File "main.py", line 8, in __init__
    self.ui = UI(self)
  File "discord_ui/client.py", line 1038, in __init__
    self.components = Components(client, auto_defer=auto_defer)
  File "discord_ui/client.py", line 810, in __init__
    elif discord.__version.startswith("1"):
AttributeError: module 'discord' has no attribute '_Components__version'

(I removed unnecessary parts of the paths)

Here's the code:

from discord.ext import commands
from discord_ui import *

class CustomBot(commands.Bot):
    def __init__(self, **options):
        super().__init__(**options)
        self.ui = UI(self)

bot = CustomBot(command_prefix="!")
bot.run("token here")

The documentation suggests that it has to be a commands.Bot, but I don't see how this would break it. Additionally, this only started happening once I updated to 3.1.0.

kvsxxx commented 2 years ago

thank you for reporting, it seems that this was a small typing issue, this should be fixed now.

kvsxxx commented 2 years ago

plz wait for the new pip package version to be uploaded together with the fix

kvsxxx commented 2 years ago

ok so I uploaded the fix with version 3.2.4

pip install discord-ui==3.2.4