diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py index 649fbd48d..543086446 100644 --- a/discord/ext/tasks/__init__.py +++ b/discord/ext/tasks/__init__.py @@ -41,6 +41,7 @@ class Loop: self._before_loop = None self._after_loop = None self._is_being_cancelled = False + self._has_failed = False self._stop_next_iteration = False if self.count is not None and self.count <= 0: @@ -89,7 +90,8 @@ class Loop: except asyncio.CancelledError: self._is_being_cancelled = True raise - except Exception as e: + except Exception: + self._has_failed = True log.exception('Internal background task failed.') raise finally: @@ -97,6 +99,7 @@ class Loop: self._is_being_cancelled = False self._current_loop = 0 self._stop_next_iteration = False + self._has_failed = False def __get__(self, obj, objtype): if obj is None: @@ -155,7 +158,7 @@ class Loop: before stopping via :meth:`clear_exception_types` or use :meth:`cancel` instead. - .. versionadded:: 1.2 + .. versionadded:: 1.2.0 """ if self._task and not self._task.done(): self._stop_next_iteration = True @@ -254,6 +257,13 @@ class Loop: """:class:`bool`: Whether the task is being cancelled.""" return self._is_being_cancelled + def failed(self): + """:class:`bool`: Whether the internal task has failed. + + .. versionadded:: 1.2.0 + """ + return self._has_failed + def before_loop(self, coro): """A decorator that registers a coroutine to be called before the loop starts running.