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
- A Discord application + bot at https://discord.com/developers/applications.
- Bot must be in your guild (server) with the
Manage Rolespermission, and the bot role must be higher than the role you grant in the guild's role hierarchy. - Buyers must sign in via Discord OAuth in Logto so their Discord ID is on file.
Step-by-step
-
Create the bot:
- https://discord.com/developers/applications → New Application → Bot tab.
- Reset token → copy.
- Privileged Gateway Intents: none required.
-
Invite the bot to your guild (replace
<APP_ID>):https://discord.com/oauth2/authorize?client_id=<APP_ID>&scope=bot&permissions=268435456268435456=MANAGE_ROLES. -
Set env vars in
.env:DISCORD_BOT_TOKEN=MTAxx... DISCORD_GUILD_ID=123456789012345678 -
Restart the glue:
docker compose up -d glue. -
In Discord → Server Settings → Roles, drag the bot's role above the role you plan to sell.
-
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).
- Guild:
-
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.