#How to pass ids as a list in a autocomplete ?

1 messages · Page 1 of 1 (latest)

quaint cliff
#

Hi, I'm trying to make an autocomplete function to let a user choose a channel by its name and return the ids of the channel (it's fetched in a database)

async def get_game_channel_associations(
            self, ctx: discord.AutocompleteContext
    ) -> list[discord.OptionChoice]:
        """
        Get the game channels names with there ids associated from the database.
        Returns:
            A dictionary with the game channels names and their ids.
        """
        async with self.bot.database.get_session() as session:
            game_categories: list[GameCategory] = await GameCategoryManager.get_all(session)
            if not game_categories:
                return [discord.OptionChoice(
                    name="No game categories found", value=-1
                )]
            return [
                discord.OptionChoice(
                    name=game_category.name,
                    value=str(game_category.id)
                )
                for game_category in game_categories
            ]

but when I call the funciton in a slash_command I get this :

Task exception was never retrieved
 future: <Task finished name='Task-15' coro=<ApplicationCommandMixin.on_application_command_auto_complete.<locals>.callback() done, defined at /app/.venv/lib/python3.13/site-packages/discord/bot.py:876> exception=HTTPException('400 Bad Request (error code: 50035): Invalid Form Body\nIn data.choices.0.value: int53 value should be less than or equal to 9007199254740991.')>
 Traceback (most recent call last):
...
 In data.choices.0.value: int53 value should be less than or equal to 9007199254740991.
pastel ivy
#

is the option a str or int option

quaint cliff
#

How to pass ids as a list in a autocomplete ?

#

it's an str , it used ot be a int. I found out a limitation made it impossible to pass a int over 9007199254740991 so I'm enable to pass a channel id

#

so I can't figure out how to pass that channel identifier

pastel ivy
#

discord seems to think its an int option still

quaint cliff
#

hmmmm

#

I'm forcing it to be a str now the error doesn't appear anymore but I don't get any callback

#

ho after restarting discord it worked !

#

weird I didn't changed the returned type

#

I guess it was a typing issue

#

thank you