Discord Bot – 'discord' has no attribute 'Select'

huangapple go评论54阅读模式
英文:

Discord Bot - 'discord' has no attribute 'Select'

问题

Here's the translated code part without the error message:

@tree.command(guild=discord.Object(id=id_do_servidor), name='menu', description='Menu')
async def sm(interaction: discord.Interaction):
    await interaction.response.send_message(
        "Escolha uma opção:",
        components=[
            discord.Select(
                placeholder="Selecione algo",
                options=[
                    discord.SelectOption(label="Opção 1", value="1"),
                    discord.SelectOption(label="Opção 2", value="2"),
                    discord.SelectOption(label="Opção 3", value="3")
                ]
            )
        ]
    )

    interaction = await tree.wait_for("select_option")
    await interaction.respond(content=f"Você selecionou a opção {interaction.values[0]}")

This code is for creating a Discord dropdown menu in a chatbot.

英文:

discord.app_commands.errors.CommandInvokeError: Command 'menu' raised an exception: AttributeError: module 'discord' has no attribute 'Select'

My code:

@tree.command(guild=discord.Object(id=id_do_servidor), name='menu', description='Menu')
async def sm(interaction: discord.Interaction):
    await interaction.response.send_message(
        "Escolha uma opção:",
        components=[
            discord.Select(
                placeholder="Selecione algo",
                options=[
                    discord.SelectOption(label="Opção 1", value="1"),
                    discord.SelectOption(label="Opção 2", value="2"),
                    discord.SelectOption(label="Opção 3", value="3")
                ]
            )
        ]
    )

    interaction = await tree.wait_for("select_option")
    await interaction.respond(content=f"Você selecionou a opção {interaction.values[0]}")

Trying to do a discord menu for chatbot, dropdown menu specifically.

答案1

得分: 1

错误应该是不言自明的

模块 'discord' 没有属性 'Select'

如果在文档中输入 select,您会发现它确实不存在:https://discordpy.readthedocs.io/en/stable/search.html?q=select

它在 ui 下,所以应该以 discord.ui.Select 的方式访问。

另外一点:

interaction = await tree.wait_for("select_option")

这并没有太多意义。您可能希望查看官方下拉示例

英文:

The error should be self-explanatory

> module 'discord' has no attribute 'Select'

If you'd type in select in the docs, you'd see that it indeed doesn't exist: https://discordpy.readthedocs.io/en/stable/search.html?q=select

It's under ui, so it should be accessed as discord.ui.Select instead.

On a side note:
> interaction = await tree.wait_for("select_option")

This doesn't make too much sense. You may want to look at the official dropdown example.

huangapple
  • 本文由 发表于 2023年3月31日 04:33:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定