Add Slash Command Autocomplete #15

Open
opened 2026-02-02 15:13:05 -05:00 by jared · 0 comments
Owner

async def minecraft_username_autocomplete(
interaction: discord.Interaction,
current: str
) -> list[app_commands.Choice[str]]:
"""Suggest previously whitelisted usernames"""
# Could query database of previous usernames
suggestions = ["Steve", "Alex", "Herobrine"] # Example
return [
app_commands.Choice(name=username, value=username)
for username in suggestions if current.lower() in username.lower()
][:25] # Discord limit

@client.tree.command(name="minecraft")
@app_commands.autocomplete(minecraft_username=minecraft_username_autocomplete)
async def minecraft(interaction: discord.Interaction, minecraft_username: str):
# ...existing code...

async def minecraft_username_autocomplete( interaction: discord.Interaction, current: str ) -> list[app_commands.Choice[str]]: """Suggest previously whitelisted usernames""" # Could query database of previous usernames suggestions = ["Steve", "Alex", "Herobrine"] # Example return [ app_commands.Choice(name=username, value=username) for username in suggestions if current.lower() in username.lower() ][:25] # Discord limit @client.tree.command(name="minecraft") @app_commands.autocomplete(minecraft_username=minecraft_username_autocomplete) async def minecraft(interaction: discord.Interaction, minecraft_username: str): # ...existing code...
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/discordBot#15