Skip to content

fix(tasks): support change_interval before first loop run #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1290.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|tasks| Correctly handle :meth:`Loop.change_interval <ext.tasks.Loop.change_interval>` when called from :meth:`~ext.tasks.Loop.before_loop` or through other means before initial loop run.
4 changes: 3 additions & 1 deletion disnake/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading