Skip to content

Commit 8e5ef7e

Browse files
authored
Merge pull request #580 from Vioshim/master
Fix to autocomplete's values (OptionChoices)
2 parents cc6d435 + e949026 commit 8e5ef7e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

discord/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,13 @@ async def autocomplete(ctx):
11061106
11071107
Parameters
11081108
-----------
1109-
values: Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
1109+
values: Union[Union[Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Callable[[:class:`AutocompleteContext`], Union[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
11101110
Possible values for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
11111111
single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
11121112
11131113
Returns
11141114
--------
1115-
Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
1115+
Callable[[:class:`AutocompleteContext`], Awaitable[Union[Iterable[:class:`OptionChoice`], Iterable[:class:`str`], Iterable[:class:`int`], Iterable[:class:`float`]]]]
11161116
A wrapped callback for the autocomplete.
11171117
"""
11181118
async def autocomplete_callback(ctx: AutocompleteContext) -> V:
@@ -1123,7 +1123,11 @@ async def autocomplete_callback(ctx: AutocompleteContext) -> V:
11231123
if asyncio.iscoroutine(_values):
11241124
_values = await _values
11251125

1126-
gen = (val for val in _values if str(val).lower().startswith(str(ctx.value or "").lower()))
1126+
def check(item: Any) -> bool:
1127+
item = getattr(item, "name", item)
1128+
return str(item).lower().startswith(str(ctx.value or "").lower())
1129+
1130+
gen = (val for val in _values if check(val))
11271131
return iter(itertools.islice(gen, 25))
11281132

11291133
return autocomplete_callback

0 commit comments

Comments
 (0)