Tasks

discord_http.tasks module

class discord_http.tasks.Loop(*, func, seconds, minutes, hours, time=None, count=None, reconnect=True)

Bases: object

Parameters:
add_exception(*exceptions) None

Adds exceptions to the whitelist of exceptions that are ignored.

Return type:

None

Parameters:

exceptions (Exception)

after_loop() Callable

Decorator that registers a custom after_loop handler for the loop.

Return type:

Callable

before_loop() Callable

Decorator that registers a custom before_loop handler for the loop.

Return type:

Callable

cancel() None

Cancels the loop if possible.

Return type:

None

property failed: bool

Returns whether the loop has failed or not.

fetch_task() Task | None

Returns the task that is running the loop.

Return type:

Task | None

handle_interval(*, seconds=0, minutes=0, hours=0, time=None) None

Sets the interval of the loop.

Parameters:
  • seconds (float | None) – Amount of seconds between each iteration of the loop

  • minutes (float | None) – Amount of minutes between each iteration of the loop

  • hours (float | None) – Amount of hours between each iteration of the loop

  • time (time | list[time] | None) – The time of day to run the loop at

Raises:
  • ValueError

    • The sleep timer cannot be 0 - count must be greater than 0 or None

  • TypeErrortime must be a datetime.time object

Return type:

None

is_being_cancelled() bool

Returns whether the loop is being cancelled or not.

Return type:

bool

is_running() bool

Returns whether the loop is running or not.

Return type:

bool

property loop_count: int

Returns the number of times the loop has been run.

on_error() Callable

Decorator that registers a custom error handler for the loop.

Return type:

Callable

remove_exception(*exceptions) None

Removes exceptions from the whitelist of exceptions that are ignored.

Return type:

None

Parameters:

exceptions (Exception)

reset_exceptions() None

Resets the whitelist of exceptions that are ignored back to the default.

Return type:

None

start(*args, **kwargs) Task

Starts the loop.

Return type:

Task

stop() None

Stops the loop.

Return type:

None

class discord_http.tasks.Sleeper(dt, *, loop)

Bases: object

Parameters:
  • dt (datetime)

  • loop (AbstractEventLoop)

cancel() None

Cancels the timer.

Return type:

None

done() bool

Returns whether the timer is done or not.

Return type:

bool

Returns:

Whether the timer is done or not

recalculate(dt) None

Recalculate the timer.

Parameters:

dt (datetime) – The new time to wait until

Return type:

None

wait() Future

Wait for the timer to finish.

Return type:

Future

Returns:

The future that is waiting for the timer to finish

discord_http.tasks.loop(*, seconds=None, minutes=None, hours=None, time=None, count=None, reconnect=True) Callable[[Callable], Loop]

Decorator that registers a function as a loop.

Parameters:
  • seconds (float | None) – The number of seconds between each iteration of the loop.

  • minutes (float | None) – The number of minutes between each iteration of the loop.

  • hours (float | None) – The number of hours between each iteration of the loop.

  • time (time | list[time] | None) – The time of day to run the loop at. (UTC only)

  • count (int | None) – The number of times to run the loop. If None, the loop will run forever.

  • reconnect (bool) – Whether the loop should reconnect if it fails or not.

Return type:

Callable[[Callable], Loop]