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)