[commands] Add commands.Greedy converter and documentation.

This allows for greedy "consume until you can't" behaviour similar to
typing.Optional but for lists.
This commit is contained in:
Rapptz
2018-09-24 03:56:32 -04:00
parent 00a445310b
commit 814b03f5a8
4 changed files with 217 additions and 2 deletions

View File

@ -179,6 +179,28 @@ Converters
.. autoclass:: discord.ext.commands.clean_content
:members:
.. class:: Greedy
A special converter that greedily consumes arguments until it can't.
As a consequence of this behaviour, most input errors are silently discarded,
since it is used as an indicator of when to stop parsing.
When a parser error is met the greedy converter stops converting, it undos the
internal string parsing routine, and continues parsing regularly.
For example, in the following code:
.. code-block:: python3
@commands.command()
async def test(ctx, numbers: Greedy[int], reason: str):
await ctx.send("numbers: {}, reason: {}".format(numbers, reason))
An invocation of ``[p]test 1 2 3 4 5 6 hello`` would pass ``numbers`` with
``[1, 2, 3, 4, 5, 6]`` and ``reason`` with ``hello``\.
For more information, check :ref:`ext_commands_special_converters`.
.. _ext_commands_api_errors:
Errors