Joshua's Docs - Chat Apps - API Notes
Light

Discord

Discord - Posting Messages via Webhook

I kind of like Discord as a central notification hub - I have a personal discord Server which only I have access to, which I use for push notifications for certain services. Fortunately, discord makes it easy to connect almost any app via webhook.

You can go to a channel, then: Edit Channel -> Integrations -> View Webhooks -> New Webhook.

You can also follow the intro guide, here

For the payload, you should follow the developer docs on Executing a Webook.

They also have a neat feature - they interoperability with the Slack webhook format - you just need to append /slack to the end of your secret webhook URL (docs).

Why is the /slack trick useful? Well, certain platforms, like Netlify, support sending notifications via Slack webhook, but don't support Discords format, so now you can just add /slack to your Discord webhook, plug it in, and Netlify won't know the different.

Example code: Calling Discord Webhook with fetch (or `node-fetch`)
const res = await fetch('https://discord.com/api/webhooks/{webhook.id}/{webhook.token}', {
	method: 'POST',
	headers: {
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
		content: 'Hello!'
	})
});
Markdown Source Last Updated:
Thu Apr 15 2021 19:38:07 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Thu Apr 15 2021 18:57:39 GMT+0000 (Coordinated Universal Time)
© 2024 Joshua Tzucker, Built with Gatsby
Feedback