英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论