-
-
Save AaronKow/3efd09b7c3accacbd885b4b17f5dddf9 to your computer and use it in GitHub Desktop.
An example gist to send Embed messages via Discord Webhooks
This file contains hidden or 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
| const axios = require("axios") | |
| //An array of Discord Embeds. | |
| let embeds = [ | |
| { | |
| title: "Discord Webhook Example", | |
| color: 5174599, | |
| footer: { | |
| text: `📅 ${date}`, | |
| }, | |
| fields: [ | |
| { | |
| name: "Field Name", | |
| value: "Field Value" | |
| }, | |
| ], | |
| }, | |
| ]; | |
| //Stringify the embeds using JSON.stringify() | |
| let data = JSON.stringify({ embeds }); | |
| //Create a config object for axios, you can also use axios.post("url", data) instead | |
| var config = { | |
| method: "POST", | |
| url: webhook, // https://discord.com/webhook/url/here | |
| headers: { "Content-Type": "application/json" }, | |
| data: data, | |
| }; | |
| //Send the request | |
| axios(config) | |
| .then((response) => { | |
| console.log("Webhook delivered successfully"); | |
| return response; | |
| }) | |
| .catch((error) => { | |
| console.log(error); | |
| return error; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment