Last active
December 30, 2023 05:21
-
-
Save marcustyphoon/977c8ce46b58d73cd73bbf0412ce5a14 to your computer and use it in GitHub Desktop.
Tip: Cloudflare Workers don't save logs, so you can only access them in real time... unless you make a Discord webhook out of a muted channel in your personal server and send them over there!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I had to switch to `"types": ["@cloudflare/workers-types/experimental"]` in tsconfig.json to get this to typecheck. | |
let id: string, token: string; | |
export const logAndWebhook = (message: string) => { | |
console.info(message); | |
navigator.sendBeacon( | |
`https://discord.com/api/webhooks/${id}/${token}`, | |
new Blob( | |
[ | |
JSON.stringify({ | |
content: `**${botName}**: ${message}`, | |
}), | |
], | |
{ type: 'application/json' }, | |
), | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment