Cron jobs
A cron job runs on a Cron Trigger. Add the schedule to your Wrangler configuration, then add a job with the same expression to cron in bot():
{ "triggers": { "crons": ["0 9 * * *"] },}import { bot } from 'botflare';
const REPORTS_CHANNEL = '123456789012345678';
export default bot({ commands: [], cron: { '0 9 * * *': async (c) => { const error = await c.send(REPORTS_CHANNEL, 'Good morning', { embeds: [{ title: 'Daily report', description: 'All systems normal' }], }); if (error) console.error(error); }, },});- The key must match the expression in
triggers.cronsexactly. c.send(channelId, text, options)posts withDISCORD_TOKEN. It takes the same message options asreply, and returns anErrorif Discord refuses.c.controlleris theScheduledControllerfrom Cloudflare, withscheduledTimeandcron.- If the bot has a
gateway, every Cron Trigger also starts the gateway connection when it is down.
Try a job locally
Section titled “Try a job locally”Start Wrangler with --test-scheduled, then call the scheduled handler:
npx wrangler dev --test-scheduledcurl "http://localhost:8787/__scheduled?cron=0+9+*+*+*"