diff --git a/didier/utils/timer.py b/didier/utils/timer.py index ae72df4..306c073 100644 --- a/didier/utils/timer.py +++ b/didier/utils/timer.py @@ -44,8 +44,12 @@ class Timer: """Replace the current task if necessary""" # If there is a current (pending) task, and the new timer is sooner than the # pending one, cancel it - if self._task is not None and not self._task.done() and self.upcoming_timer > event.timestamp: - self._task.cancel() + if self._task is not None and not self._task.done(): + if self.upcoming_timer > event.timestamp: + self._task.cancel() + else: + # The new task happens after the existing task, it has to wait for its turn + return self._task = self.client.loop.create_task(self.end_timer(endtime=event.timestamp, event_id=event.event_id)) self.upcoming_timer = event.timestamp @@ -54,4 +58,6 @@ class Timer: async def end_timer(self, *, endtime: datetime, event_id: int): """Wait until a timer runs out, and then trigger an event to send the message""" await discord.utils.sleep_until(endtime) + self.upcoming_timer = None + self.upcoming_event_id = None self.client.dispatch("timer_end", event_id)