Discord Webhooks for getting data
Posted on:
Often I decide I want to run some small node script to grab some data, and then the results over to Discord. Discord itself allows you to do such extremely quickly via a Discord webhook. Discord has an Intro to Webhooks support page to go fetch the url to throw it against GitHub, but you can just use this endpoint with an HTTP post request. For example, this is all needed:
const discordWebhookUrl = "https://discord.com/...";
fetch(discordWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ content: "Hello world!" }),
});
And then I could first fetch some data from some other API above, and then point a cronjob and the automation is done.
Some examples I've done with this:
- Check if any access tokens from various sites are expired and send a post if they have.
- Check trading card prices.
- Check when was the last time I posted onto my blog.
Discord has a lot better app capabilities, but if I just want a simple pipeline from some data into Discord, using a webhook is straightforward.