1. Go to this page and download the library: Download tempcord/tasks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tempcord / tasks example snippets
use Tempcord\Plugins\Tasks\Attributes\Task;
#[Task(interval: 10)]
final readonly class SweepTemporaryMessages
{
public function __construct(private TempMessages $messages) {}
public function __invoke(): void
{
$this->messages->sweep();
}
}
final readonly class Housekeeping
{
#[Task(interval: 10)]
public function sweepMessages(): void {}
#[Task(cron: '@daily')]
public function pruneStatistics(): void {}
}
#[Task(
interval: 300, // run every this many seconds
cron: '0 * * * *', // or on a cron schedule; the two are mutually exclusive
runOnBoot: true, // also take a turn as the bot starts, rather than waiting out
// the first interval
name: 'custom-name', // what to call it in the logs and in tasks:list
enabled: true, // false leaves it out of the schedule entirely
)]
use function Tempcord\Plugins\Tasks\tasks;
use function Tempcord\Plugins\Tasks\cancelTask;
use function Tempcord\Plugins\Tasks\taskStats;
taskStats()['SweepTemporaryMessages']->getSuccessRate();
cancelTask('SweepTemporaryMessages');