让您的团队在他们已经协作的地方保持信息通畅。Discord 集成将支付、订阅、争议和其他重要事件直接发送到您选择的任何频道—无需轮询或仪表板。
本指南假设您可以访问 Dodo Payments 仪表板的集成部分。
开始使用
打开 Webhook 部分
在您的 Dodo Payments 仪表板中,打开 Webhooks → + 添加端点,展开下拉菜单以显示集成。 选择 Discord
选择 Discord 卡片,然后点击 连接您的 Discord 工作区。
授权机器人
授予请求的权限,以便机器人可以在您选择的频道中发布消息。
编辑转换代码
根据您的需求定制有效负载 → 嵌入映射,或从下面的模板开始。
测试并创建
使用示例有效负载预览嵌入,然后点击 创建。
完成!
🎉 您的 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 对象。
- 在编辑器中验证您的代码—语法错误将阻止交付。
- 确保字段名称与 webhook 有效负载结构匹配。