Benjamin Lannon

Select a theme. Click on the overlay or the button again to exit

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:

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.

References

Discord Webhook Reference