24 lines
907 B
JavaScript
24 lines
907 B
JavaScript
// 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
|
||
}]
|
||
})
|
||
});
|
||
}
|