Hello! So i am trying to create a type of API with Cloudflare Workers and i a time of my code i need to send a Discord Webhook and this doens’t work on any way!
I Already tried everything with Request or Fetch and they doens’t work.
Wrangler: Last Version
Node Version: 18.9.0
My Funcition:
async function sendWebhook(webhook, content, title, fields, banner, color) {
let body = {};
body.content = 'teste';
body.embeds = [];
body.embeds[0] = {}
body.embeds[0].title = title;
body.embeds[0].image = banner;
body.embeds[0].author = { name: name, iconURL: logo, url: 'https://megarthur.tech' };
body.embeds[0].footer = { text: `${name} - © Copyright ${new Date().getFullYear()}`, iconURL: logo };
body.embeds[0].color = color;
body.embeds[0].thumbnail = logo;
body.embeds[0].fields = fields;
console.log('Sending Request to Discord API');
try {
const response = await fetch(webhook, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=utf-8' },
body: JSON.stringify(body),
});
//console.log(response.json())
console.log('Sended response for Discord API');
} catch (err) {
console.log(err)
}
}