У меня есть API для разногласий, который публикует guild_count бота. Он работал раньше, но когда я пытаюсь снова, теперь он отправляет ошибку ошибка
вот код на стороне пользователя с использованием node-fetch:
const body = { count: client.guilds.size };
fetch(`https://cloudlist.xyz/api/stats/${client.user.id}`, {
method: "POST",
headers: {
Authorization: "api_token",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
}).then(res => res.json())
.then(async response => {
console.log(response)
})
А вот серверный пост api:
app.post("/api/stats/:id", limiter ,async (req, res) => {
console.log(req.params)
let botId = req.params.id;
let auth = req.headers.authorization;
if (!auth)
return res.json({
success: "false",
error: "Authorization header not found."
});
let count = req.body.count ? req.body.count : req.body.server_count;
if (!count)
return res.json({ success: "false", error: "Count not found in body." });
count = parseInt(count);
if (!count)
return res.json({ success: "false", error: "Count not integer." });
const bot = await client.fetchUser(`${botId}`);
if (!bot) return res.json({ success: "false", error: "Bot not found." });
// if (!bot.auth) return res.json({ "success": "false", "error": "Create a bot authorization token." });
//if (bot.auth !== auth) return res.json({ "success": "false", "error": "Incorrect authorization token." });
if (bot) {
database.ref(`Bots/${botId}`).once("value", async function(snapshot) {
if (snapshot.val() === null)
return res.json({ success: "false", error: "Bot not found." });
if (snapshot.val().apiKey != auth) {
return res.json({
success: "false",
error: "Incorrect authorization token."
});
} else {
database
.ref(`Bots/${botId}`)
.update({
guilds_count: `${count}`
})
res.json({bot: count });
}
});
}
});
Кстати, я использую body-parser для обоих, чтобы убедиться, что я получаю ответ json