Skip to content

Commit 1cef90a

Browse files
authored
Add @slash_command.autocomplete() example. (#101)
1 parent 5b1a1a6 commit 1cef90a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

examples/slash_commands/param.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async def constraint(
154154
async def autocomplete_langs(
155155
inter: disnake.ApplicationCommandInteraction, string: str
156156
) -> List[str]:
157-
return list(filter(lambda lang: string in lang.lower(), LANGUAGES))
157+
return [lang for lang in LANGUAGES if string in lang.lower()]
158158

159159

160160
@bot.slash_command()
@@ -165,6 +165,21 @@ async def autocomplete(
165165
...
166166

167167

168+
# From version 2.2.0
169+
# it's possible to create autocomplete options with the decorator @slash_command.autocomplete()
170+
171+
172+
@bot.slash_command()
173+
async def languages(inter: disnake.ApplicationCommandInteraction, language: str):
174+
...
175+
176+
177+
@languages.autocomplete("language")
178+
async def language_autocomp(inter: disnake.ApplicationCommandInteraction, string: str):
179+
string = string.lower()
180+
return [lang for lang in LANGUAGES if string in lang.lower()]
181+
182+
168183
# You can use docstrings to set the description of the command or even
169184
# the description of options. You should follow the ReStructuredText or numpy format.
170185
@bot.slash_command()

0 commit comments

Comments
 (0)