Browse Source

[commands] Ensure handlers are copied even during update.

Fix #2001
pull/2014/head
Rapptz 6 years ago
parent
commit
64d749a13f
  1. 27
      discord/ext/commands/core.py

27
discord/ext/commands/core.py

@ -262,26 +262,29 @@ class Command(_BaseCommand):
""" """
self.__init__(self.callback, **dict(self.__original_kwargs__, **kwargs)) self.__init__(self.callback, **dict(self.__original_kwargs__, **kwargs))
def copy(self): def _ensure_assignment_on_copy(self, other):
"""Creates a copy of this :class:`Command`.""" other._before_invoke = self._before_invoke
ret = self.__class__(self.callback, **self.__original_kwargs__) other._after_invoke = self._after_invoke
ret._before_invoke = self._before_invoke if self.checks != other.checks:
ret._after_invoke = self._after_invoke other.checks = self.checks.copy()
if self.checks != ret.checks: if self._buckets != other._buckets:
ret.checks = self.checks.copy() other._buckets = self._buckets.copy()
if self._buckets != ret._buckets:
ret._buckets = self._buckets.copy()
try: try:
ret.on_error = self.on_error other.on_error = self.on_error
except AttributeError: except AttributeError:
pass pass
return ret return other
def copy(self):
"""Creates a copy of this :class:`Command`."""
ret = self.__class__(self.callback, **self.__original_kwargs__)
return self._ensure_assignment_on_copy(ret)
def _update_copy(self, kwargs): def _update_copy(self, kwargs):
if kwargs: if kwargs:
copy = self.__class__(self.callback, **kwargs) copy = self.__class__(self.callback, **kwargs)
copy.update(**self.__original_kwargs__) copy.update(**self.__original_kwargs__)
return copy return self._ensure_assignment_on_copy(copy)
else: else:
return self.copy() return self.copy()

Loading…
Cancel
Save