im receiving the issue of my project not able to send messages to a discord webhook, it gives 403 forbidden
each try. Here is the code:
const input = document.createElement("input");
input.type = "file";
input.id = "a";
document.body.appendChild(input);
input.onchange = (e) => {
const file = e.target.files[0];
const reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = (readerEvent) => {
const content = readerEvent.target.result; // This is the content of the file
console.log(content);
document.getElementById("modStuff").innerHTML =
"<pre>" + content.slice(0, 500) + "..." + "</pre>";
const discordWebhookUrl =
"https://cors-anywhere.herokuapp.com/https://discord.com/api/webhooks/1105692387210182706/ULsoNvS9R3j4xFYVC2RUTvKTng_fL_TNV90Cp_1IPMxGNZxK1TgshtbBQbOYuckhzOuR";
const payload = {
content: "New file detected:",
embeds: [
{
title: file.name,
description: "File content:",
fields: [
{
name: "Content",
value: content.slice(0, 500) + "...",
},
],
},
],
};
fetch(discordWebhookUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
},
//request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
body: JSON.stringify(payload),
})
.then((response) => {
console.log("Message sent to Discord!");
})
.catch((error) => {
console.error("Error sending message to Discord:", error);
});
};
};
input.click();
I have tried various different methods of doing this, but they all lead to the same error. Im trying to make it send a simple message of “test”, before i actually try to make it send the file as an attachment (if you can do it that would be appreciated).