diff --git a/changelog/1290.bugfix.rst b/changelog/1290.bugfix.rst new file mode 100644 index 0000000000..67bc1c7138 --- /dev/null +++ b/changelog/1290.bugfix.rst @@ -0,0 +1 @@ +|tasks| Correctly handle :meth:`Loop.change_interval ` when called from :meth:`~ext.tasks.Loop.before_loop` or through other means before initial loop run. diff --git a/disnake/ext/tasks/__init__.py b/disnake/ext/tasks/__init__.py index f421562b15..07a0673f8b 100644 --- a/disnake/ext/tasks/__init__.py +++ b/disnake/ext/tasks/__init__.py @@ -689,7 +689,9 @@ def change_interval( self._time = self._get_time_parameter(time) self._sleep = self._seconds = self._minutes = self._hours = MISSING - if self.is_running(): + # `_last_iteration` can be missing if `change_interval` gets called in `before_loop` or + # before the event loop ticks after `start()` + if self.is_running() and self._last_iteration is not MISSING: if self._time is not MISSING: # prepare the next time index starting from after the last iteration self._prepare_time_index(now=self._last_iteration)