Add improved docs for slash commands (#77)

* Fix command checks actually working

* Current progress on slash command docs

* Improve docs for slash commands further
This commit is contained in:
Gnome!
2021-09-27 09:14:07 +01:00
committed by GitHub
parent d16d2d856f
commit 3260ec6643
7 changed files with 172 additions and 66 deletions

View File

@ -1008,27 +1008,50 @@ class Greedy(List[T]):
return cls(converter=converter)
if TYPE_CHECKING:
class Option(Generic[T, DT]): # type: ignore
"""A special 'converter' to apply a description to slash command options.
For example in the following code:
.. code-block:: python3
@bot.command()
async def ban(ctx,
member: discord.Member, *,
reason: str = commands.Option('no reason', description='the reason to ban this member')
):
await member.ban(reason=reason)
The description would be ``the reason to ban this member`` and the default would be ``no reason``
.. versionadded:: 2.0
Attributes
------------
default: Optional[Any]
The default for this option, overwrites Option during parsing.
description: :class:`str`
The description for this option, is unpacked to :attr:`.Command.option_descriptions`
"""
description: DT
default: Union[T, inspect._empty]
__slots__ = (
"default",
"description",
)
def __init__(self, default: T = inspect.Parameter.empty, *, description: DT) -> None:
self.description = description
self.default = default
if TYPE_CHECKING:
# Terrible workaround for type checking reasons
def Option(default: T = inspect.Parameter.empty, *, description: str) -> T:
...
else:
class Option(Generic[T, DT]):
description: DT
default: Union[T, inspect.Parameter.empty]
__slots__ = (
"default",
"description",
)
def __init__(self, default: T = inspect.Parameter.empty, *, description: DT) -> None:
self.description = description
self.default = default
def _convert_to_bool(argument: str) -> bool:
lowered = argument.lower()
if lowered in ("yes", "y", "true", "t", "1", "enable", "on"):

View File

@ -132,7 +132,7 @@ application_option_type_lookup = {
discord.Member,
discord.User,
): 6, # Preferably discord.abc.User, but 'Protocols with non-method members don't support issubclass()'
(discord.abc.GuildChannel, discord.DMChannel): 7,
(discord.abc.GuildChannel, discord.Thread): 7,
discord.Role: 8,
float: 10,
}
@ -330,11 +330,16 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
This overwrites the global ``slash_commands`` parameter of :class:`.Bot`.
.. versionadded:: 2.0
slash_command_guilds: Optional[:class:`List[int]`]
slash_command_guilds: Optional[List[:class:`int`]]
If this is set, only upload this slash command to these guild IDs.
This overwrites the global ``slash_command_guilds`` parameter of :class:`.Bot`.
.. versionadded:: 2.0
option_descriptions: Dict[:class:`str`, :class:`str`]
The unpacked option descriptions from :class:`.Option`.
.. versionadded:: 2.0
"""
__original_kwargs__: Dict[str, Any]