mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-13 05:15:22 +00:00
Validate and bind parent in Group.add_command
This commit is contained in:
parent
7c0a9e901d
commit
5b8bcaff73
@ -872,7 +872,8 @@ class Group:
|
|||||||
The command or group is already registered. Note that the :attr:`CommandAlreadyRegistered.guild_id`
|
The command or group is already registered. Note that the :attr:`CommandAlreadyRegistered.guild_id`
|
||||||
attribute will always be ``None`` in this case.
|
attribute will always be ``None`` in this case.
|
||||||
ValueError
|
ValueError
|
||||||
There are too many commands already registered.
|
There are too many commands already registered or the group is too
|
||||||
|
deeply nested.
|
||||||
TypeError
|
TypeError
|
||||||
The wrong command type was passed.
|
The wrong command type was passed.
|
||||||
"""
|
"""
|
||||||
@ -880,10 +881,19 @@ class Group:
|
|||||||
if not isinstance(command, (Command, Group)):
|
if not isinstance(command, (Command, Group)):
|
||||||
raise TypeError(f'expected Command or Group not {command.__class__!r}')
|
raise TypeError(f'expected Command or Group not {command.__class__!r}')
|
||||||
|
|
||||||
|
if isinstance(command, Group) and self.parent is not None:
|
||||||
|
# In a tree like so:
|
||||||
|
# <group>
|
||||||
|
# <self>
|
||||||
|
# <group>
|
||||||
|
# this needs to be forbidden
|
||||||
|
raise ValueError('groups can only be nested at most one level')
|
||||||
|
|
||||||
if not override and command.name in self._children:
|
if not override and command.name in self._children:
|
||||||
raise CommandAlreadyRegistered(command.name, guild_id=None)
|
raise CommandAlreadyRegistered(command.name, guild_id=None)
|
||||||
|
|
||||||
self._children[command.name] = command
|
self._children[command.name] = command
|
||||||
|
command.parent = self
|
||||||
if len(self._children) > 25:
|
if len(self._children) > 25:
|
||||||
raise ValueError('maximum number of child commands exceeded')
|
raise ValueError('maximum number of child commands exceeded')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user