When using fetch or Request to post Discord WebHook doesn't work

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)
			}
		}

This is very non-specific. Can you elaborate on what exactly isn’t working? What error are you seeing?

This doesn’t have an error that shows on the Console of Wrangler, but the function (Fetch or Request) doesn’t send the webhook to Discord API. The fetch or request function doesn’t send the Request to the Internet they just ignore.

What data are you passing to the sendWebhook function?

After some verification of the Worker the code below is executed

sendWebhook(
				success.webhook,
				'✅ Authorized',
				[
					{
						name: '`📱` Version:',
						value: `${data.version}`,
						inline: true,
					},
					{
						name: '`💻` License:',
						value: `${data.license}`,
						inline: true,
					},
					{
						name: '`🔢` License IP:',
						value: `${license.ip}`,
						inline: true,
					},
					{
						name: '`🎮` Local IP:',
						value: `${user_ip}`,
						inline: true,
					},
					{
						name: '`🎨` Lifetime:',
						value: `${license.version}`,
						inline: true,
					},
					{
						name: '`🎯` Modules:',
						value: `\`${license.modules}\``,
						inline: true,
					},
					{
						name: '`🎫` Data:',
						value: `\`\`\`json\n${JSON.stringify(data)}\`\`\``,
						inline: false,
					},
				],
				success.banner,
				success.color
			);

Assuming success.webhook is a valid URL I can’t see anything that would stop await fetch() from doing a POST.

Are you saying ‘Sended response for Discord API’ it not logged to the console? And that no error is caught and logged either?

Sometimes the ‘Sended response for Discord API’ is displayed but this doesn’t work anyway

This is a test and the ‘Sended response for Discord API’ was sent to console but doesn’t is recived in discord Server

Are you running wrangler with --remote?

No its on Local Mode. And when its on remote doesn’t work

How are you calling sendWebhook inside the worker?

This is above but i will send

Use in Worker after some Verifications:

sendWebhook(
				success.webhook,
				'✅ Authorized',
				[
					{
						name: '`📱` Version:',
						value: `${data.version}`,
						inline: true,
					},
					{
						name: '`💻` License:',
						value: `${data.license}`,
						inline: true,
					},
					{
						name: '`🔢` License IP:',
						value: `${license.ip}`,
						inline: true,
					},
					{
						name: '`🎮` Local IP:',
						value: `${user_ip}`,
						inline: true,
					},
					{
						name: '`🎨` Lifetime:',
						value: `${license.version}`,
						inline: true,
					},
					{
						name: '`🎯` Modules:',
						value: `\`${license.modules}\``,
						inline: true,
					},
					{
						name: '`🎫` Data:',
						value: `\`\`\`json\n${JSON.stringify(data)}\`\`\``,
						inline: false,
					},
				],
				success.banner,
				success.color
			);

The success config: (The code isn’t have the ***** its just for an example)

const success = {
	webhook: 'https://canary.discord.com/api/webhooks/*****',
	banner: 'https://cdn.discordapp.com/attachments/******',
	color: '#0000FF',
};

No idea.

Hi, i have the same problem.

{
	"url": "/api/contact",
	"statusCode": 500,
	"statusMessage": "",
	"message": "[POST] \"/\": <no response> Fetch API cannot load: ",
	"stack": ""
}

here is my code: https://github.com/dev-cetus/cetus-is-a-dev/blob/main/server/api/contact.post.ts