diff options
| author | Rapptz <[email protected]> | 2019-03-20 22:38:00 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2019-03-20 22:38:00 -0400 |
| commit | 64d749a13fc6960e155572335ce5379be9fff59f (patch) | |
| tree | e7422bfc8508d6092de31bb9cdb6a72bbe53eeb2 | |
| parent | Drop websockets version due to issues. (diff) | |
| download | discord.py-64d749a13fc6960e155572335ce5379be9fff59f.tar.xz discord.py-64d749a13fc6960e155572335ce5379be9fff59f.zip | |
[commands] Ensure handlers are copied even during update.
Fix #2001
| -rw-r--r-- | discord/ext/commands/core.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 3074e0ca..7ca200ec 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -262,26 +262,29 @@ class Command(_BaseCommand): """ self.__init__(self.callback, **dict(self.__original_kwargs__, **kwargs)) - def copy(self): - """Creates a copy of this :class:`Command`.""" - ret = self.__class__(self.callback, **self.__original_kwargs__) - ret._before_invoke = self._before_invoke - ret._after_invoke = self._after_invoke - if self.checks != ret.checks: - ret.checks = self.checks.copy() - if self._buckets != ret._buckets: - ret._buckets = self._buckets.copy() + def _ensure_assignment_on_copy(self, other): + other._before_invoke = self._before_invoke + other._after_invoke = self._after_invoke + if self.checks != other.checks: + other.checks = self.checks.copy() + if self._buckets != other._buckets: + other._buckets = self._buckets.copy() try: - ret.on_error = self.on_error + other.on_error = self.on_error except AttributeError: 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): if kwargs: copy = self.__class__(self.callback, **kwargs) copy.update(**self.__original_kwargs__) - return copy + return self._ensure_assignment_on_copy(copy) else: return self.copy() |