mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
Update attributes of instantiated Group to point to the Command copy
This commit is contained in:
parent
56e0c1b3d7
commit
9d27855755
@ -619,19 +619,21 @@ class Group:
|
|||||||
The parent group. ``None`` if there isn't one.
|
The parent group. ``None`` if there isn't one.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__discord_app_commands_group_children__: ClassVar[List[Union[Command, Group]]] = []
|
__discord_app_commands_group_children__: ClassVar[Dict[str, Union[Command, Group]]] = {}
|
||||||
__discord_app_commands_group_name__: str = MISSING
|
__discord_app_commands_group_name__: str = MISSING
|
||||||
__discord_app_commands_group_description__: str = MISSING
|
__discord_app_commands_group_description__: str = MISSING
|
||||||
|
|
||||||
def __init_subclass__(cls, *, name: str = MISSING, description: str = MISSING) -> None:
|
def __init_subclass__(cls, *, name: str = MISSING, description: str = MISSING) -> None:
|
||||||
cls.__discord_app_commands_group_children__ = children = [
|
cls.__discord_app_commands_group_children__ = children = {
|
||||||
member for member in cls.__dict__.values() if isinstance(member, (Group, Command)) and member.parent is None
|
name: member
|
||||||
]
|
for name, member in cls.__dict__.items()
|
||||||
|
if isinstance(member, (Group, Command)) and member.parent is None
|
||||||
|
}
|
||||||
|
|
||||||
found = set()
|
found = set()
|
||||||
for child in children:
|
for child in children.values():
|
||||||
if child.name in found:
|
if child.name in found:
|
||||||
raise TypeError(f'Command {child.name} is a duplicate')
|
raise TypeError(f'Command {child.name!r} is a duplicate')
|
||||||
found.add(child.name)
|
found.add(child.name)
|
||||||
|
|
||||||
if name is MISSING:
|
if name is MISSING:
|
||||||
@ -666,12 +668,13 @@ class Group:
|
|||||||
|
|
||||||
self.parent: Optional[Group] = parent
|
self.parent: Optional[Group] = parent
|
||||||
|
|
||||||
self._children: Dict[str, Union[Command, Group]] = {
|
self._children: Dict[str, Union[Command, Group]] = {}
|
||||||
child.name: child._copy_with_binding(self) for child in self.__discord_app_commands_group_children__
|
|
||||||
}
|
|
||||||
|
|
||||||
for child in self._children.values():
|
for attr, child in self.__discord_app_commands_group_children__.items():
|
||||||
|
child = child._copy_with_binding(self)
|
||||||
child.parent = self
|
child.parent = self
|
||||||
|
self._children[child.name] = child
|
||||||
|
setattr(self, attr, child)
|
||||||
|
|
||||||
if parent is not None and parent.parent is not None:
|
if parent is not None and parent.parent is not None:
|
||||||
raise ValueError('groups can only be nested at most one level')
|
raise ValueError('groups can only be nested at most one level')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user