Skip to content

Instantly share code, notes, and snippets.

@marcustyphoon
Last active December 30, 2023 05:21
Show Gist options
  • Save marcustyphoon/977c8ce46b58d73cd73bbf0412ce5a14 to your computer and use it in GitHub Desktop.
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!
// 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