代码之家  ›  专栏  ›  技术社区  ›  skee

创建下拉菜单时出现不和谐.py关键字错误

  •  0
  • skee  · 技术社区  · 1 年前

    所以我创建了一个命令来发送一个带有一些名称的下拉菜单,当使用关键字时 discord.SelectMenu 我在它的关键字中得到一个错误 custom_id 这是代码

    @tree.command(name="troops", description="shows list of troops")
    async def troops(interaction):
      mydb.execute("SELECT name FROM troops")
      result = mydb.fetchall()
      options = [discord.SelectOption(label=row[0], value=row[0]) for row in result]
    
      menu = discord.SelectMenu(custom_id= "troop_menu", placeholder="select a troop", options=options)
      row = discord.ActionRow(menu)
      await interaction.response.send_message("Select a troop:", components=[row])
    

    而我得到的错误是

    discord.app_commands.errors.CommandInvokeError: Command 'troops' raised an exception: TypeError: SelectMenu.__init__() got an unexpected keyword argument 'custom_id'
    

    此外,我还得到了一个错误,说 Expected 1 more positional argumen custom_id = "troop_menu"

    0 回复  |  直到 1 年前