Add extras attribute to app commands command types

This commit is contained in:
I. Ahmad
2022-06-21 17:38:56 -07:00
committed by GitHub
parent 868476c999
commit 9fc4769b18
2 changed files with 47 additions and 3 deletions

View File

@ -837,6 +837,7 @@ class CommandTree(Generic[ClientT]):
nsfw: bool = False,
guild: Optional[Snowflake] = MISSING,
guilds: Sequence[Snowflake] = MISSING,
extras: dict = MISSING,
) -> Callable[[CommandCallback[Group, P, T]], Command[Group, P, T]]:
"""Creates an application command directly under this tree.
@ -860,6 +861,9 @@ class CommandTree(Generic[ClientT]):
The list of guilds to add the command to. This cannot be mixed
with the ``guild`` parameter. If no guilds are given at all
then it becomes a global command instead.
extras: :class:`dict`
A dictionary that can be used to store extraneous data.
The library will not touch any values or keys within this dictionary.
"""
def decorator(func: CommandCallback[Group, P, T]) -> Command[Group, P, T]:
@ -880,6 +884,7 @@ class CommandTree(Generic[ClientT]):
callback=func,
nsfw=nsfw,
parent=None,
extras=extras,
)
self.add_command(command, guild=guild, guilds=guilds)
return command
@ -893,6 +898,7 @@ class CommandTree(Generic[ClientT]):
nsfw: bool = False,
guild: Optional[Snowflake] = MISSING,
guilds: Sequence[Snowflake] = MISSING,
extras: dict = MISSING,
) -> Callable[[ContextMenuCallback], ContextMenu]:
"""Creates a application command context menu from a regular function directly under this tree.
@ -930,6 +936,9 @@ class CommandTree(Generic[ClientT]):
The list of guilds to add the command to. This cannot be mixed
with the ``guild`` parameter. If no guilds are given at all
then it becomes a global command instead.
extras: :class:`dict`
A dictionary that can be used to store extraneous data.
The library will not touch any values or keys within this dictionary.
"""
def decorator(func: ContextMenuCallback) -> ContextMenu:
@ -937,7 +946,7 @@ class CommandTree(Generic[ClientT]):
raise TypeError('context menu function must be a coroutine function')
actual_name = func.__name__.title() if name is MISSING else name
context_menu = ContextMenu(name=actual_name, nsfw=nsfw, callback=func)
context_menu = ContextMenu(name=actual_name, nsfw=nsfw, callback=func, extras=extras)
self.add_command(context_menu, guild=guild, guilds=guilds)
return context_menu