Fixed embed error

This commit is contained in:
PxlLoewe
2025-06-24 20:18:27 -07:00
parent f8389383f8
commit 9ea2593159

View File

@@ -9,59 +9,64 @@ if (!process.env.DISCORD_REPORT_CHANNEL)
const router: Router = Router(); const router: Router = Router();
router.post("/admin-embed", async (req, res) => { router.post("/admin-embed", async (req, res) => {
const { reportId } = req.body; try {
if (!reportId) { const { reportId } = req.body;
res.status(400).json({ error: "reportId is required" }); if (!reportId) {
return; res.status(400).json({ error: "reportId is required" });
} return;
const report = await prisma.report.findUnique({ }
where: { const report = await prisma.report.findUnique({
id: Number(reportId), where: {
}, id: Number(reportId),
include: {
Reported: true,
Sender: true,
},
});
if (!report) {
res.status(404).json({ error: "Report not found" });
return;
}
const embed = new EmbedBuilder()
.setTitle(`Report #${report.id}`)
.setURL(`${process.env.NEXT_PUBLIC_HUB_URL}/admin/report/${report.id}`)
.setDescription(report.text)
.addFields(
{
name: "gemeldeter Nutzer",
value: `${report.Reported?.firstname} ${report.Reported?.lastname} (${report.Reported?.publicId})`,
inline: true,
}, },
{ name: "angemeldet als", value: report.reportedUserRole, inline: true }, include: {
{ Reported: true,
name: "gemeldet von", Sender: true,
value: `${report.Sender?.firstname} ${report.Sender?.lastname} (${report.Sender?.publicId})`,
}, },
) });
.setFooter({
text: "",
})
.setTimestamp(new Date(report.timestamp))
.setColor("DarkRed");
const reportsChannel = await client.channels.fetch(process.env.DISCORD_REPORT_CHANNEL!); if (!report) {
if (!reportsChannel || !reportsChannel.isSendable()) { res.status(404).json({ error: "Report not found" });
res.status(500).json({ error: "Reports channel not found or is not a text channel" }); return;
return; }
const embed = new EmbedBuilder()
.setTitle(`Report #${report.id}`)
.setURL(`${process.env.NEXT_PUBLIC_HUB_URL}/admin/report/${report.id}`)
.setDescription(report.text)
.addFields(
{
name: "gemeldeter Nutzer",
value: `${report.Reported?.firstname} ${report.Reported?.lastname} (${report.Reported?.publicId})`,
inline: true,
},
{ name: "angemeldet als", value: report.reportedUserRole, inline: true },
{
name: "gemeldet von",
value: `${report.Sender?.firstname} ${report.Sender?.lastname} (${report.Sender?.publicId})`,
},
)
.setFooter({
text: "Bitte reagiere mit 🫡, wenn du den Report bearbeitet hast, oder mit ✅, wenn er abgeschlossen ist.",
})
.setTimestamp(new Date(report.timestamp))
.setColor("DarkRed");
const reportsChannel = await client.channels.fetch(process.env.DISCORD_REPORT_CHANNEL!);
if (!reportsChannel || !reportsChannel.isSendable()) {
res.status(500).json({ error: "Reports channel not found or is not a text channel" });
return;
}
const message = await reportsChannel.send({ embeds: [embed] });
message.react("🫡").catch(console.error);
message.react("✅").catch(console.error);
res.json({
message: "Report embed sent to Discord channel",
});
} catch (error) {
console.error("Error sending report embed:", error);
res.status(500).json({ error: "Failed to send report embed" });
} }
const message = await reportsChannel.send({ embeds: [embed] });
message.react("🫡").catch(console.error);
message.react("✅").catch(console.error);
res.json({
message: "Report embed sent to Discord channel",
});
}); });
export default router; export default router;