fixed playername completion on /commands

This commit is contained in:
2023-06-29 12:38:31 +02:00
parent ce602c517d
commit 27925b0eb0
2 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ class SlashLeaderboard(commands.Cog):
for server_choice in servers.keys():
if(current.lower() in server_choice.lower()):
data.append(app_commands.Choice(name=server_choice, value=server_choice))
return data
return data[:25]
@leaderboard.autocomplete("board")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
@@ -63,7 +63,7 @@ class SlashLeaderboard(commands.Cog):
for board_choice in boards:
if(current.lower() in board_choice.lower()):
data.append(app_commands.Choice(name=board_choice, value=board_choice))
return data
return data[:25]
async def setup(client):
await client.add_cog(SlashLeaderboard(client))
+17 -2
View File
@@ -51,6 +51,21 @@ class SlashStats(commands.Cog):
await interaction.response.send_message(embed=botmessage)
@stats.autocomplete("playernames")
async def autocomplete_player(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
async with aiohttp.ClientSession() as session:
async with session.get('https://tone.sleepycat.date/v2/client/players') as r:
players = await r.json()
for player_choice in players.keys():
try:
if(current.lower() in players[player_choice]['username'].lower()):
data.append(app_commands.Choice(name=players[player_choice]['username'], value=players[player_choice]['username']))
except AttributeError:
pass
return data[:25]
@stats.autocomplete("weapon")
async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
@@ -58,7 +73,7 @@ class SlashStats(commands.Cog):
for weapon_choice in weaponlist:
if(current.lower() in weapon_choice.lower()):
data.append(app_commands.Choice(name=weapon_choice, value=weapon_choice))
return data
return data[:25]
@stats.autocomplete("servername")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
@@ -70,7 +85,7 @@ class SlashStats(commands.Cog):
for server_choice in servers.keys():
if(current.lower() in server_choice.lower()):
data.append(app_commands.Choice(name=server_choice, value=server_choice))
return data
return data[:25]