Skip to content

Commit

Permalink
Implementing auto complete for stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
DMcP89 committed Jan 30, 2024
1 parent f0c88f0 commit db9fd1a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions harambot/cogs/yahoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,31 @@ async def trade(self, interaction: discord.Interaction):
await response_message.add_reaction(yes_emoji)
await response_message.add_reaction(no_emoji)

@set_yahoo
async def stats_autocomplete(
self,
interaction: discord.Interaction,
current: str,
) -> List[app_commands.Choice[str]]:
players = self.yahoo_api.league().player_details(current)
if players:
options = list(
map(
lambda x: app_commands.Choice(
name=x["name"]["full"],
value=x["name"]["full"],
),
players,
)
)
else:
options = []
return options

@app_commands.command(
name="stats", description="Returns the details of the given player"
)
@app_commands.autocomplete(player_name=stats_autocomplete)
@set_yahoo
async def stats(self, interaction: discord.Interaction, player_name: str):
logger.info("player_details called")
Expand Down

0 comments on commit db9fd1a

Please sign in to comment.