You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/app_commands/slash_autocomplete.py
+15-4Lines changed: 15 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -85,19 +85,24 @@
85
85
"yellowgreen",
86
86
]
87
87
88
-
BASIC_ALLOWED= [123, 444, 55782] # this would be a list of discord user IDs
88
+
BASIC_ALLOWED= [...] # this would normally be a list of discord user IDs for the purpose of this example
89
89
90
90
91
-
# Simple example of using logic in a basic_autocomplete callback. In this case, we're only returning any results if the user's ID exists in the BASIC_ALLOWED list
color: Option(str, "Pick a color from this big list", autocomplete=discord.utils.basic_autocomplete(color_searcher)),
133
-
animal: Option(str, "Pick an animal from this small list", autocomplete=discord.utils.basic_autocomplete(["snail", "python", "cricket", "orca"])),
138
+
color: Option(str, "Pick a color from this big list", autocomplete=discord.utils.basic_autocomplete(color_searcher)),# Demonstrates passing a callback to discord.utils.basic_autocomplete
139
+
animal: Option(str, "Pick an animal from this small list", autocomplete=discord.utils.basic_autocomplete(["snail", "python", "cricket", "orca"])),# Demonstrates passing a static iterable discord.utils.basic_autocomplete
134
140
):
141
+
"""This demonstrates using the discord.utils.basic_autocomplete helper function.
142
+
For the `color` option, a callback is passed, where additional logic can be added to determine which values are returned.
143
+
For the `animal` option, a static iterable is passed.
144
+
While a small amount of values for `animal` are used in this example, iterables of any length can be passed to discord.utils.basic_autocomplete
145
+
Note that the basic_autocomplete function itself will still only return a maximum of 25 items."""
135
146
awaitctx.respond(f"You picked {color} as your color, and {animal} as your animal!")
0 commit comments