diff --git a/cogs/calendar.py b/cogs/calendar.py index 89adbd5..f76f6f4 100644 --- a/cogs/calendar.py +++ b/cogs/calendar.py @@ -19,7 +19,7 @@ FIRESTORE_CALENDAR = ( DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$") TIME_RE = re.compile(r"^\d{2}:\d{2}$") -from .calendar_data import COUNTRY_TZ, tz_choices +from .calendar_data import COUNTRY_TZ, country_autocomplete class Calendar(commands.Cog): @@ -43,7 +43,7 @@ class Calendar(commands.Cog): title="Event title", description="Extra notes (optional)", ) - @app_commands.choices(country=tz_choices()) + @app_commands.autocomplete(country=country_autocomplete) async def book_cmd( self, interaction: discord.Interaction, diff --git a/cogs/calendar_data.py b/cogs/calendar_data.py index 2bbf2c1..eba2aec 100644 --- a/cogs/calendar_data.py +++ b/cogs/calendar_data.py @@ -48,7 +48,16 @@ COUNTRY_TZ: dict[str, float] = { # fmt: on -def tz_choices() -> list: - """Return app_commands.Choice list for the country dropdown.""" +async def country_autocomplete( + _interaction, + current: str, +) -> list: + """Return matching countries for slash-command autocomplete.""" from discord import app_commands - return [app_commands.Choice(name=c, value=c) for c in sorted(COUNTRY_TZ)] + current = current.lower() + matches = [ + app_commands.Choice(name=c, value=c) + for c in sorted(COUNTRY_TZ) + if current in c.lower() + ] + return matches[:25] # Discord limits to 25 suggestions