#slash command Option raises AttributeError

1 messages · Page 1 of 1 (latest)

heady dock
#

I'm trying to create a slash command to upload a file

In order to attach a file in a slash command I'm using the discord.Option typehint with discord.Attachment as the type

class MyCog(Cog):
    ...

    @slash_command(name="upload-file", description="Upload some file")
    async def slash_command_load_quiz(
            self,
            ctx: ApplicationContext,
            file: discord.Option(
                discord.Attachment,
                description="The file to upload",
                required=True)
            ):
        await ctx.response.send_message("...")

The Cog is loaded via the load_extension function

When starting the bot, I get the following error

...
    option = Option(option)
  File "/Users/luis1/Library/Python/3.8/lib/python/site-packages/discord/commands/options.py", line 226, in __init__
    self.input_type = SlashCommandOptionType.from_datatype(input_type)
  File "/Users/luis1/Library/Python/3.8/lib/python/site-packages/discord/enums.py", line 779, in from_datatype
    if datatype.__name__ in ["Member", "User"]:
AttributeError: 'str' object has no attribute '__name__'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File ".../main.py", line 30, in <module>
    main()
  File ".../main.py", line 24, in main
    bot.load_extension(extension)
  File "/Users/luis1/Library/Python/3.8/lib/python/site-packages/discord/cog.py", line 913, in load_extension
    self._load_from_module_spec(spec, name)
  File "/Users/luis1/Library/Python/3.8/lib/python/site-packages/discord/cog.py", line 794, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'extension' raised an error: AttributeError: 'str' object has no attribute '__name__'

I tried to replicate the bug, but weirdly enough, it works when I try to replicate it...

Anyway, I noticed that in discord/commands/options.py:227 the input_type variable usually holds the type in this case it would be <class 'discord.Message.Attachment'>, whereas in my case it holds the string 'discord.Option(discord.Attachment, description="The file to upload", required=True)'

I'm using Python3.8 and the latest (unstable) version of py-cord from #library-updates

Would be nice to know if I'm just stupid, or it's actually an issue with the library...

also happens if I replace discord.Attachment with str (did not check for any other valid types)

inner ivy
#

Can you show the pip list?

#

also you can remove the str at the attachment

heady dock
#
py-cord @ git+https://github.com/Pycord-Development/pycord.git@f5d0f2292061313e4f6f2f4f5daa3185830f0dfa
heady dock
inner ivy
#

Wtf is that Version?

#

?tag install

quaint ospreyBOT
#
  1. Uninstall discord.py or any other forks of discord.py you might have with the namespace discord.
    python -m pip uninstall discord.py discord -y

2a. Install py-cord
python -m pip install py-cord

2b. Update py-cord
python pip install -U py-cord

Installing other builds:
Note: You need to have git installed. Use ?tag git to find out how to install git.

Updating the module to master branch (unstable):
pip install -U git+https://github.com/Pycord-Development/pycord

heady dock
#

it's the unstable master branch as announced in #library-updates

#

or if you would follow the last step in the installation guide above

#

f5d0f2292061313e4f6f2f4f5daa3185830f0dfa is the commit

inner ivy
#

Can you show the full pip list pls?

#

pip list > pip.txt should create a file for you

heady dock
#
administrator==0.0.0
aiohttp==3.7.4.post0
asgiref==3.5.0
async-timeout==3.0.1
attrs==21.2.0
backports.zoneinfo==0.2.1
certifi==2022.12.7
cffi==1.14.6
chardet==4.0.0
click==8.1.3
clipboard==0.0.4
colored==1.4.3
coverage==6.4.4
Django==4.0.3
duckdb==0.7.1
embed==0.1.0
exceptiongroup==1.1.2
extra==0.0.0.20200726
idna==2.10
image==1.5.33
inflection==0.5.1
iniconfig==2.0.0
invoke==1.6.0
loguru==0.6.0
lxml==4.6.3
multidict==5.1.0
numpy==1.21.2
packaging==23.1
pandas==1.3.3
Pillow==9.1.0
pluggy==1.2.0
profanityfilter==2.0.6
py-cord @ git+https://github.com/Pycord-Development/pycord.git@f5d0f2292061313e4f6f2f4f5daa3185830f0dfa
pycparser==2.20
PyNaCl==1.4.0
pyperclip==1.8.1
pyphen==0.11.0
pytest==7.4.0
python-dateutil==2.8.2
python-dotenv==0.20.0
pytz==2021.3
requests==2.25.1
selenium==3.141.0
six==1.16.0
sqlparse==0.4.2
textstat==0.7.2
tomli==2.0.1
typing_extensions==4.5.0
urllib3==1.25.11
yarl==1.6.3
youtube-dl==2021.6.6
knotty ruin
#

you cant use that with smth: discord.Option

#

try using the decorator @discord.option

knotty ruin
heady dock
#

Oh that could be the case

inner ivy
knotty ruin
heady dock