---
title: Sell a Discord role for crypto
description: A Discord bot that creates a GaaPay payment link for a role, posts an ephemeral checkout button, and grants the role only after a verified payment.succeeded webhook.
url: https://gaapay.com/integrations/discord
updated: 2026-12-04
language: en
type: guide
---

# Sell a Discord role for crypto

> Two moving parts: a bot that creates an order per interaction, and a webhook endpoint that grants the role. The bot never sees the API secret if both live behind the same backend — and they should.

Discord communities are a natural fit for stablecoin payments: the buyer is already online, the goods are digital, and a card checkout with chargebacks is a poor match for a $5 role.

The failure mode is equally natural: granting the role from the bot’s chat interaction instead of from a verified payment event. Anyone can click a button; only the webhook proves money moved.

## 1 · The slash command

```mjs
import { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder } from 'discord.js';

export const data = new SlashCommandBuilder()
  .setName('buyrole')
  .setDescription('Buy the VIP role with USDT or USDC')
  .addStringOption(o => o.setName('tier').setDescription('monthly or lifetime').setRequired(true));

export async function execute(interaction) {
  await interaction.deferReply({ ephemeral: true });
  const tier = interaction.options.getString('tier');
  const res = await fetch(`${BACKEND}/discord/checkout`, {
    method: 'POST',
    headers: { 'content-type': 'application/json' },
    body: JSON.stringify({
      guild: interaction.guildId,
      user: interaction.user.id,
      tier,
    }),
  });
  const { checkout_url, order_id } = await res.json();

  const embed = new EmbedBuilder()
    .setTitle('Complete your purchase')
    .setDescription(`Order \`${order_id}\` · the role is granted automatically after payment.`);
  const row = new ActionRowBuilder().addComponents(
    new ButtonBuilder().setLabel('Pay with crypto').setStyle(5).setURL(checkout_url));

  await interaction.editReply({ embeds: [embed], components: [row] });
}
```

> **Why ephemeral:** — a public checkout URL is a public order. Ephemeral replies keep the payment link tied to the user who asked, which makes support and refunds tractable.

## 2 · Grant on the webhook

The backend receives `payment.succeeded`, verifies the signature, looks up the Discord user and guild from the order metadata, then calls the Discord API to add the role. It stores the event id so a retry cannot grant twice.

Membership changes are not payment events: if the user leaves the server, the role disappears with them, and a lifetime purchase needs a re-grant on rejoin — handle that in your own membership flow.

## Discord pitfalls

- **Do not grant from the button interaction.** A button click is not a payment.
- **Rate limits are real.** Role changes are API calls; queue them and handle 429 with backoff.
- **Store user + guild in metadata.** You will need them for support, refunds and re-grants.
- **Refunds should revoke.** A merchant-initiated refund is a revoke event; do it in the same service that grants.

## Discord questions

### Do I need a server?

Yes, for the webhook and the secret. The bot process alone cannot verify payments safely unless it also hosts the endpoint.

### Can I sell subscriptions?

Yes, with a role expiry job. Crypto has no recurring mandate; a “monthly” role is a dated entitlement you renew by asking the user to pay again.

### What about chargebacks?

There are none on-chain. Your refund policy is the only reversal path, which is why it must be explicit before purchase.

[Node guide](/integrations/node) — **Build the webhook endpoint**: The verification code is the same as any server integration — timestamp, raw body, constant-time compare.

## Related

- https://gaapay.com/integrations/node
- https://gaapay.com/docs/verify
- https://gaapay.com/pricing
- https://gaapay.com/compare
