NextCord:使用转换器在Slash命令中使用转换器的错误

发布于 2025-01-22 10:31:50 字数 3100 浏览 0 评论 0原文

我有discord.py和pycord的背景,我决定尝试NextCord Slash命令 因此,我决定创建一些命令,在此中,我收到了一个特殊的错误消息

@slash_command(name='suggestions_set', guild_ids=[956174862815199252])
async def suggestions_set(self, interaction: Interaction, channel: TextChannel):
   db.insert({'channel': channel.id})
   await interaction.send(f'**The suggestions channel has been set to {channel.mention}**')

,我收到以下错误:

Traceback (most recent call last):
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 675, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\angel\Code\Python\spybot\cogs\info.py", line 6, in <module>
    class Info(Cog):
  File "C:\Users\angel\Code\Python\spybot\cogs\info.py", line 10, in Info
    async def suggestions_set(self, interaction: Interaction, channel: SlashOption):
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 1981, in decorator
    app_cmd = ApplicationCommand(
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 1418, in __init__
    super().__init__(
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 602, in __init__
    self._from_callback(callback)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 820, in _from_callback
    arg = CommandOption(param, self)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 327, in __init__
    self.type: ApplicationCommandOptionType = self.get_type(parameter.annotation)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 384, in get_type
    raise NotImplementedError(
NotImplementedError: Type "<class 'nextcord.application_command.SlashOption'>" isn't a supported typing for Application Commands.

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

Traceback (most recent call last):
  File "C:\Users\angel\Code\Python\spybot\bot.py", line 19, in <module>
    bot.load_extension(f'cogs.{file[:-3]}')
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 789, in load_extension
    self._load_from_module_spec(spec, name, extras=extras)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 678, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
nextcord.ext.commands.errors.ExtensionFailed: Extension 'cogs.info' raised an error: NotImplementedError: Type "<class 'nextcord.application_command.SlashOption'>" isn't a supported typing for Application Commands.

我知道这一定是某种类型的实现错误,但我不明白,如果有人能告诉我我在做什么错?

I have a background with discord.py and pycord, and I decided to try nextcord slash commands
so I decided to create some commands, in this I got a peculiar error message

@slash_command(name='suggestions_set', guild_ids=[956174862815199252])
async def suggestions_set(self, interaction: Interaction, channel: TextChannel):
   db.insert({'channel': channel.id})
   await interaction.send(f'**The suggestions channel has been set to {channel.mention}**')

I got the following error:

Traceback (most recent call last):
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 675, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\angel\Code\Python\spybot\cogs\info.py", line 6, in <module>
    class Info(Cog):
  File "C:\Users\angel\Code\Python\spybot\cogs\info.py", line 10, in Info
    async def suggestions_set(self, interaction: Interaction, channel: SlashOption):
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 1981, in decorator
    app_cmd = ApplicationCommand(
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 1418, in __init__
    super().__init__(
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 602, in __init__
    self._from_callback(callback)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 820, in _from_callback
    arg = CommandOption(param, self)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 327, in __init__
    self.type: ApplicationCommandOptionType = self.get_type(parameter.annotation)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\application_command.py", line 384, in get_type
    raise NotImplementedError(
NotImplementedError: Type "<class 'nextcord.application_command.SlashOption'>" isn't a supported typing for Application Commands.

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

Traceback (most recent call last):
  File "C:\Users\angel\Code\Python\spybot\bot.py", line 19, in <module>
    bot.load_extension(f'cogs.{file[:-3]}')
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 789, in load_extension
    self._load_from_module_spec(spec, name, extras=extras)
  File "C:\Users\angel\anaconda3\envs\spybot\lib\site-packages\nextcord\ext\commands\bot.py", line 678, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
nextcord.ext.commands.errors.ExtensionFailed: Extension 'cogs.info' raised an error: NotImplementedError: Type "<class 'nextcord.application_command.SlashOption'>" isn't a supported typing for Application Commands.

I understand this must be some type implementations error but I don't understand it, If someone could tell what I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

破晓 2025-01-29 10:31:50

频道:textChannel = slashoption(...)应根据其 github存储库

channel: TextChannel = SlashOption(...) should work according to the examples in their github repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文