Thanks a lot, I wanted to implement this feature on my bot and I searched a lot but could not find anything about it then I saw your video and oh God, it was a relief!
How would you add 2 arguments where the options displayed for the second one are dependent on the choice of the first. Like first argument could be "state" and depending on that the second one displays the cities in that state .
@@bubfusion HELLO! late reply lmao So this depends a LOT on how you want to do it and the ammount of data you want to filter. The basic gist of it is to store outside of the command the `data` variable so, for example, lets say that the first field for me is "Character" and the second one is "Item" The first autocomplete will list all of the user's characters, and the second one will list the chosen character inventory by Item name, and we will asume that we already have the logic for both autocompletes to query this data. at the top of your file, over where your commands are but below where your intents (or cog class) you create a dict, lets call this "chosen_character", so, for example, self.chosen_character = {} Then, in the function that handles the first autocomplete, define "chosen_character" to the value of data, something like; self.chosen_character[user_id] = data[0].value if data else None and then in your second autocomplete, you call what you stored before using it; character_id = self.chosen_character.get(user_id, "value") This requires you to add to both functions the following at the begining: user_id = str(interaction.user.id) because otherwise it will store ONE character for everyone and if 2 users use the command at the same time it will break the second autocomplete for one of them. Also, you should reset the dict every time the command ends executing so that if someone goes directly to the second field, it doesnt keep the value of the last time they used the command. THIS IS JUST PROOF OF CONCEPT, literally did this since i saw this comments. There are probably much better ways to do this, and also it has the problem that when the command is written, chosen_character will always default to the first result on the query or the first item of the list, and if the user clicks on something on the list without writing, the bot has no idea it happened for some reason and the second autocomplete will filter/query based off the first item instead of what the user chose. Right now I think there might be a way to solve this listening to the interaction with an event handler? or maybe modifying the autocomplete to not show anything until its written, its up to you to decide what workaround works best
I just do "from typing import Literal" and "async def server_command(self, interaction: discord.Interaction, option:Literal['Restart', 'Stop']):" does the same thing without autocomplete function
Can i use insted of items to load list from enum class event list? And load only 25 first and then of user try to type in something in the option, the bot will give new choice results based on matches in enum list?
for example if you want to load data from a database which may be different every time you run the command or when searching the web via a command or sth
Thanks a lot, I wanted to implement this feature on my bot and I searched a lot but could not find anything about it then I saw your video and oh God, it was a relief!
Countless hours spent searching the internet and no results. This video summed up what I wanted to do perfectly. Thank you!
Your work helps me a lot thanks! Don't stop this
Thanks! The docs aren't the most helpful sometimes, this was excellent.
Thanks, i was stuck for hours.
How would you add 2 arguments where the options displayed for the second one are dependent on the choice of the first. Like first argument could be "state" and depending on that the second one displays the cities in that state .
Did you ever figure it out? I'm trying to do the same thing
@@bubfusion HELLO! late reply lmao
So this depends a LOT on how you want to do it and the ammount of data you want to filter. The basic gist of it is to store outside of the command the `data` variable
so, for example, lets say that the first field for me is "Character" and the second one is "Item"
The first autocomplete will list all of the user's characters, and the second one will list the chosen character inventory by Item name, and we will asume that we already have the logic for both autocompletes to query this data.
at the top of your file, over where your commands are but below where your intents (or cog class) you create a dict, lets call this "chosen_character", so, for example,
self.chosen_character = {}
Then, in the function that handles the first autocomplete, define "chosen_character" to the value of data, something like;
self.chosen_character[user_id] = data[0].value if data else None
and then in your second autocomplete, you call what you stored before using it;
character_id = self.chosen_character.get(user_id, "value")
This requires you to add to both functions the following at the begining: user_id = str(interaction.user.id)
because otherwise it will store ONE character for everyone and if 2 users use the command at the same time it will break the second autocomplete for one of them.
Also, you should reset the dict every time the command ends executing so that if someone goes directly to the second field, it doesnt keep the value of the last time they used the command.
THIS IS JUST PROOF OF CONCEPT, literally did this since i saw this comments. There are probably much better ways to do this, and also it has the problem that when the command is written, chosen_character will always default to the first result on the query or the first item of the list, and if the user clicks on something on the list without writing, the bot has no idea it happened for some reason and the second autocomplete will filter/query based off the first item instead of what the user chose.
Right now I think there might be a way to solve this listening to the interaction with an event handler? or maybe modifying the autocomplete to not show anything until its written, its up to you to decide what workaround works best
I just do "from typing import Literal" and
"async def server_command(self, interaction: discord.Interaction, option:Literal['Restart', 'Stop']):"
does the same thing without autocomplete function
How could I do this dynamically? Like to get the currently loaded cogs?
Figured it out like 5 minutes later lmao.
I'm doing exactly the same thing as you and I can't get autocomplete on discord.
i have a error "TypeError: issubclass() arg 1 must be a class". how can i fix that?
Can i use insted of items to load list from enum class event list? And load only 25 first and then of user try to type in something in the option, the bot will give new choice results based on matches in enum list?
i belive if u breake the for loop at 25 items that should work
Even simple slash commands with Literals do autocomplete automatically without this. Why do we need separate autocomplete command?
for example if you want to load data from a database which may be different every time you run the command or when searching the web via a command or sth
Great video. Do you know how to add a description to an option?
The app_commands.Choice does not allow for a description, only localized names and values.
However, the SelectOption has a description attribute.
TypeError: unknown parameter given: item