Skip to content

Commit 9ebbcc4

Browse files
committed
Amend the filter parameter docstring
* Clarify the description of the ``filter`` parameter * Add usage examples for the ``filter`` parameter
1 parent 540c527 commit 9ebbcc4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

discord/utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,8 @@ def basic_autocomplete(
13241324
Possible values for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a
13251325
single argument of :class:`.AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`.
13261326
filter: Optional[Callable[[:class:`.AutocompleteContext`, Any], Union[:class:`bool`, Awaitable[:class:`bool`]]]]
1327-
Predicate callable (sync or async) used to filter the autocomplete options. This function should accept two arguments:
1328-
the :class:`.AutocompleteContext` and an item from ``values``. If ``None`` is provided, a default filter is used that includes items whose string representation starts with the user's input value, case-insensitive.
1327+
An optional callable (sync or async) used to filter the autocomplete options. It accepts two arguments:
1328+
the :class:`.AutocompleteContext` and an item from ``values`` iteration treated as callback parameters. If ``None`` is provided, a default filter is used that includes items whose string representation starts with the user's input value, case-insensitive.
13291329
13301330
.. versionadded:: 2.7
13311331
@@ -1338,9 +1338,11 @@ def basic_autocomplete(
13381338
----
13391339
Autocomplete cannot be used for options that have specified choices.
13401340
1341-
Example
1341+
Examples
13421342
-------
13431343
1344+
Basic usage:
1345+
13441346
.. code-block:: python3
13451347
13461348
Option(str, "color", autocomplete=basic_autocomplete(("red", "green", "blue")))
@@ -1352,6 +1354,12 @@ async def autocomplete(ctx):
13521354
13531355
Option(str, "name", autocomplete=basic_autocomplete(autocomplete))
13541356
1357+
With filter parameter:
1358+
1359+
.. code-block:: python3
1360+
1361+
Option(str, "color", autocomplete=basic_autocomplete(("red", "green", "blue"), filter=lambda c, i: str(c.value or "") in i))
1362+
13551363
.. versionadded:: 2.0
13561364
"""
13571365

0 commit comments

Comments
 (0)