Tasks
cronjob
#
Loop
#
Loop(callback: TaskCallbackT, delay_seconds: float)
Bases: Task
set_interval
#
set_interval(
timedelta: _timedelta | None = None,
*,
hours: int = 0,
minutes: int = 0,
seconds: int = 0
) -> None
Cancel the currently scheduled task and schedule the next task and future tasks with a new wait time.
Example#
from datetime import datetime
import crescent
from crescent.ext import tasks
bot = hikari.GatewayBot("...")
client = crescent.Client(bot)
@client.include
@tasks.loop(seconds=1)
async def my_task():
print(datetime.now())
@client.include
@crescent.command
async def set_interval(ctx: crescent.Context, interval: int):
print(f"setting new interval to {interval}")
my_task.metadata.set_interval(seconds=interval)
await ctx.respond(f"Set new interval to {interval}s")
loop
#
loop(
timedelta: _timedelta | None = None,
*,
hours: int = 0,
minutes: int = 0,
seconds: int = 0
) -> retT
Run a callback when the bot is started and every time the specified time interval has passed.