Tasks

discord_http.tasks module

class discord_http.tasks.Loop(*, func: Callable, seconds: float | None, minutes: float | None, hours: float | None, time: time | list[time] | None = None, count: int | None = None, reconnect: bool = True)[source]

Bases: object

add_exception(*exceptions: Exception) None[source]

Adds exceptions to the whitelist of exceptions that are ignored

after_loop() Callable[source]

Decorator that registers a custom after_loop handler for the loop

before_loop() Callable[source]

Decorator that registers a custom before_loop handler for the loop

cancel() None[source]

Cancels the loop if possible

property failed: bool

Returns whether the loop has failed or not

fetch_task() Task | None[source]

Returns the task that is running the loop

handle_interval(*, seconds: float | None = 0, minutes: float | None = 0, hours: float | None = 0, time: time | list[time] | None = None) None[source]

Sets the interval of the loop.

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

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

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

  • time (dtime) – 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

is_being_cancelled() bool[source]

Returns whether the loop is being cancelled or not

is_running() bool[source]

Returns whether the loop is running or not

property loop_count: int

Returns the number of times the loop has been run

on_error() Callable[source]

Decorator that registers a custom error handler for the loop

remove_exception(*exceptions: Exception) None[source]

Removes exceptions from the whitelist of exceptions that are ignored

reset_exceptions() None[source]

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

start(*args, **kwargs) Task[source]

Starts the loop

stop() None[source]

Stops the loop

class discord_http.tasks.Sleeper(dt: datetime, *, loop: AbstractEventLoop)[source]

Bases: object

cancel() None[source]
done() bool[source]
recalculate(dt: datetime) None[source]
wait() Future[source]
discord_http.tasks.loop(*, seconds: float | None = None, minutes: float | None = None, hours: float | None = None, time: time | list[time] | None = None, count: int | None = None, reconnect: bool = True) Callable[[Callable], Loop][source]

Decorator that registers a function as a loop.

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

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

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

  • time (datetime.time) – The time of day to run the loop at. (UTC only)

  • count (int) – 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.