Discord role grant

Sells access to a paid Discord role. After payment, the bot assigns the role to the buyer's Discord account.

What it does

When an order is marked paid, the glue calls PUT /guilds/{guild.id}/members/{user.id}/roles/{role.id} against the Discord HTTP API. The buyer's Discord ID comes from the Logto Discord OAuth connector profile.

Prerequisites

Step-by-step

  1. Create the bot:

    • https://discord.com/developers/applications → New Application → Bot tab.
    • Reset token → copy.
    • Privileged Gateway Intents: none required.
  2. Invite the bot to your guild (replace <APP_ID>):

    https://discord.com/oauth2/authorize?client_id=<APP_ID>&scope=bot&permissions=268435456
    

    268435456 = MANAGE_ROLES.

  3. Set env vars in .env:

    DISCORD_BOT_TOKEN=MTAxx...
    DISCORD_GUILD_ID=123456789012345678
    
  4. Restart the glue: docker compose up -d glue.

  5. In Discord → Server Settings → Roles, drag the bot's role above the role you plan to sell.

  6. In the dashboard, add an entitlement of type Discord role to your product:

    • Guild: 123456789012345678
    • Role: pick from the dropdown (the dashboard fetches roles via the bot).
  7. Enable the Discord OAuth connector in Logto admin.

Troubleshooting

| Symptom | Likely cause | |---|---| | Missing Permissions | bot role is below the target role, or bot lacks Manage Roles | | Unknown Member | buyer isn't in the guild — gate purchase on guild membership in your checkout copy | | Role assigned but user doesn't see new channels | channel-level perms override role perms; recheck channel overwrites | | 401 Unauthorized | wrong DISCORD_BOT_TOKEN, or bot was kicked |

Coming after MVP launch

Automatic guild-join via OAuth scope guilds.join, plus revocation on refund.