让您的团队在他们已经协作的地方保持信息通畅。Discord 集成将支付、订阅、争议和其他重要事件直接发送到您选择的任何频道—无需轮询或仪表板。
本指南假设您可以访问 Dodo Payments 仪表板的 Integrations 部分。
开始使用
Open the Webhook Section
在 Dodo Payments 仪表板中,打开 Webhooks → + Add Endpoint 并展开下拉菜单以显示集成。 Select Discord
选择 Discord 卡片,然后点击 Connect your Discord workspace。
Authorize the Bot
授予所需权限,使机器人能够在所选频道中发送消息。
Edit Transformation Code
根据需要调整 payload → embed 的映射,或从下面的模板开始。
Test & Create
使用示例 payload 预览 embed,然后点击 Create。
Done!
🎉 您的 Discord 频道现在将收到实时的 Dodo Payments 更新。
转换代码示例
最小支付嵌入
function handler(webhook) {
if (webhook.eventType === "payment.succeeded") {
const p = webhook.payload.data;
webhook.payload = {
embeds: [{
title: "✅ Payment Successful",
description: `**Amount:** $${(p.total_amount / 100).toFixed(2)}\n**Customer:** ${p.customer.email}`,
color: 0x2ecc71 // green
}]
};
}
return webhook;
}
订阅事件
function handler(webhook) {
const s = webhook.payload.data;
switch (webhook.eventType) {
case "subscription.active":
webhook.payload = {
embeds: [{
title: "📄 Subscription Activated",
fields: [
{ name: "Customer", value: s.customer.email, inline: true },
{ name: "Product", value: s.product_id, inline: true },
{ name: "Next Billing", value: new Date(s.next_billing_date).toLocaleDateString(), inline: true }
],
color: 0x2ecc71
}]
};
break;
case "subscription.cancelled":
webhook.payload = {
embeds: [{
title: "⚠️ Subscription Cancelled",
fields: [
{ name: "Customer", value: s.customer.email, inline: true },
{ name: "Product", value: s.product_id, inline: true }
],
color: 0xf1c40f
}]
};
break;
}
return webhook;
}
争议警报
function handler(webhook) {
if (webhook.eventType.startsWith("dispute.")) {
const d = webhook.payload.data;
webhook.payload = {
embeds: [{
title: d.dispute_status === "won" ? "🏆 Dispute Won" : d.dispute_status === "lost" ? "❌ Dispute Lost" : "🚨 Dispute Update",
fields: [
{ name: "Payment ID", value: d.payment_id, inline: true },
{ name: "Amount", value: `$${(d.amount / 100).toFixed(2)}`, inline: true },
{ name: "Status", value: d.dispute_status, inline: true }
],
color: d.dispute_status === "won" ? 0x2ecc71 : d.dispute_status === "lost" ? 0xe74c3c : 0xe67e22
}]
};
}
return webhook;
}
- 优先使用嵌入以获得丰富的格式和颜色。
- 保持标题简短;将详细信息放在字段中。
- 使用直观的颜色:绿色(成功),红色(失败),橙色(警告)。
故障排除
- 确认机器人有权访问该频道。
- 检查转换是否返回具有
embeds 的 JSON 对象。