Skip to content

Instantly share code, notes, and snippets.

@dmdboi
Last active October 8, 2023 11:09
Show Gist options
  • Save dmdboi/743111ae5945a1fe1ea558039cbe25f7 to your computer and use it in GitHub Desktop.
Save dmdboi/743111ae5945a1fe1ea558039cbe25f7 to your computer and use it in GitHub Desktop.
An example gist to send Embed messages via Discord Webhooks
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