addEventListener("scheduled", (event) => {
event.waitUntil(handleScheduled(event));
});
async function handleScheduled(event) {
const originalCurrentTime = new Date(event.scheduledTime);
await sendToDiscord(DEBUG_CHANNEL, `Last triggered at: ${currentTime}`);
}
async function sendToDiscord(webhookUrl, message) {
// Send the message and get the response
// If the response is not 200, log the error
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: message }),
});
// Check if the response status is in the 200-204 range
if (response.status >= 200 && response.status <= 204) {
console.log("Message sent successfully to Discord.");
} else {
// If the response status is not in the success range, log the error
console.error(
`Error sending message to Discord. Status: ${response.status}, Message: ${message}`
);
// Also log the response body for further investigation
const responseBody = await response.text();
console.error(`Response Body: ${responseBody}`);
}
}
addEventListener("scheduled", (event) => {
event.waitUntil(handleScheduled(event));
});
async function handleScheduled(event) {
const originalCurrentTime = new Date(event.scheduledTime);
await sendToDiscord(DEBUG_CHANNEL, `Last triggered at: ${currentTime}`);
}
async function sendToDiscord(webhookUrl, message) {
// Send the message and get the response
// If the response is not 200, log the error
const response = await fetch(webhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: message }),
});
// Check if the response status is in the 200-204 range
if (response.status >= 200 && response.status <= 204) {
console.log("Message sent successfully to Discord.");
} else {
// If the response status is not in the success range, log the error
console.error(
`Error sending message to Discord. Status: ${response.status}, Message: ${message}`
);
// Also log the response body for further investigation
const responseBody = await response.text();
console.error(`Response Body: ${responseBody}`);
}
}