Main_Website-Oblistudios/discord.js

24 lines
907 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// discord.js
import fetch from "node-fetch";
const WEBHOOK_URL = process.env.DISCORD_WEBHOOK_URL;
export async function sendDiscordOrder({ user, items, total, refund = false }) {
const lines = items.map(i => `${i.qty} × ${i.name} ($${i.price.toFixed(2)})`).join("\n");
const title = refund ? "REFUND processed" : "New order paid";
const buyer = user?.discord_username || "unknown";
await fetch(WEBHOOK_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
username: "Shop Bot",
embeds: [{
title,
description: `${lines}\n\nTotal: **$${total?.toFixed(2) ?? "—"}**`,
footer: { text: `Buyer: ${buyer} (ID ${user?.discord_user_id ?? "?"})` },
color: refund ? 0xcc3333 : 0x33cc66
}]
})
});
}