Discord access
Give roles in your Discord server with a checkout, payment link, invoice, plan, subscription or checkout session, send buyers to connect their Discord account, and read who has access.
On this page
How Discord access works
A business that has added Railbed's bot to its Discord server can sell roles there: the buyer connects their Discord account before paying, and the bot gives the roles once the payment settles and takes them back when the access ends. The Paid Discord server guide covers connecting a server and choosing roles in the dashboard. This page covers the same thing through the API:
- Set
discord_accesson a checkout, payment link, invoice, subscription plan, subscription or checkout session, and read it back on the same object. - For a session your own checkout starts, send the buyer to its
discord_connect_urlto connect Discord, then start it. - Read the servers you've connected, and each purchase's access and its status.
- Receive
discord.access.*webhook events as access is given, changed and ended.
Servers are connected only in the dashboard, under Integrations → Discord. The API never calls Discord: it reads what Railbed already knows and saves the rule, and the bot does the rest. Where Discord access isn't available yet, objects carry no discord_access field, the reads on this page answer 404 not_found, and sending discord_access is 400 unknown_field. A product with no Discord access leaves the field out either way.
The Discord access rule
discord_access on a product says which server's roles a purchase gives and for how long. Objects without Discord access leave the field out.
| Field | Type | Description |
|---|---|---|
server | object | The server: id (Discord's server id) and name |
roles | array | The roles a purchase gives, one to five: each id (Discord's role id) and name |
plan_roles | object or null | A pricing table's roles for each plan, keyed by plan id, when they differ by plan. null otherwise |
duration_days | integer or null | How many days a one-time purchase gives access, 1 to 3,650. null for access that doesn't run out, and always null on plans and subscriptions, whose access lasts while the subscription is paid |
on_end | string | What happens when access ends: remove_roles, or kick to also remove the member from the server |
reminders | boolean | Whether members who ask for it get a message in Discord before an invoice is due or a dated pass ends. Never sent for access that doesn't run out |
{
"id": "pay_Dc4mQ8vT2nXr6KpZw1Lb",
"object": "checkout_session",
"url": "https://pay.railbed.io/p/pay_Dc4mQ8vT2nXr6KpZw1Lb",
"status": "open",
"livemode": false,
"amount": "49.00",
"currency": "USD",
"description": "Guild Hall membership, 30 days",
"reference": "member_1042",
"customer_email": "buyer@example.com",
"created": 1790380525,
"expires_at": 1790466925,
"started_at": null,
"metadata": null,
"order_id": "ord_Lr7xN2qW9tKc4VmZp6Hs",
"collect": null,
"canceled_at": null,
"checkout_id": null,
"plan_label": null,
"payment_methods": [
"card",
"crypto"
],
"crypto_url": "https://pay.railbed.io/p/pay_Dc4mQ8vT2nXr6KpZw1Lb?method=crypto",
"routing": {
"choice": "buyer",
"provider": null,
"fallback": true
},
"discord_access": {
"server": {
"id": "1180429738155892816",
"name": "Guild Hall"
},
"roles": [
{
"id": "1180431102246014986",
"name": "Member"
}
],
"plan_roles": null,
"duration_days": 30,
"on_end": "remove_roles",
"reminders": true
},
"discord_connect_url": "https://pay.railbed.io/p/pay_Dc4mQ8vT2nXr6KpZw1Lb"
}Setting Discord access
Send discord_access on Create or Update of a checkout, payment link, invoice, subscription plan or subscription, or on Create a checkout session:
| Field | Type | Description |
|---|---|---|
server | string | Required. The Discord server id, from List Discord servers |
roles | array of strings | Required. One to five Discord role ids in that server |
plan_roles | object | A pricing table only: role ids for each plan id, for plans that give other roles |
duration_days | integer or null | A one-time purchase only: days of access, 1 to 3,650. Leave it out or send null for access that doesn't run out. Not taken on plans and subscriptions |
on_end | string | remove_roles (the default) or kick. kick needs the bot to have Kick Members in that server |
reminders | boolean | Default true |
accept_powers | array of strings | Role ids you mean to give even though they carry moderation powers in the server. Without them, a new role with powers is 400 discord_role_warning; a role the rule already gives needs no repeat |
holders | string | Sent without server, takes the access off: keep (members who have access keep it until it ends) or remove (their access ends now) |
Send discord_access: null to take the access off. Members who already have access keep it until it ends. To end their access now as well, send { "holders": "remove" } instead of null. Sending the rule a product already has changes nothing.
curl https://pay.railbed.io/v1/checkouts \
-H "Authorization: Bearer $RAILBED_SECRET_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Guild Hall membership",
"amount": "10.00",
"currency": "USD",
"discord_access": {
"server": "1180429738155892816",
"roles": ["1180431102246014986"],
"duration_days": 30
}
}'const checkout = await fetch('https://pay.railbed.io/v1/checkouts', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RAILBED_SECRET_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Guild Hall membership',
amount: '10.00',
currency: 'USD',
discord_access: { server: '1180429738155892816', roles: ['1180431102246014986'], duration_days: 30 },
}),
}).then((r) => r.json());checkout = requests.post(
"https://pay.railbed.io/v1/checkouts",
headers={"Authorization": f"Bearer {os.environ['RAILBED_SECRET_KEY']}"},
json={
"name": "Guild Hall membership",
"amount": "10.00",
"currency": "USD",
"discord_access": {"server": "1180429738155892816", "roles": ["1180431102246014986"], "duration_days": 30},
},
timeout=15,
).json()The rule is checked as the dashboard checks it, and an error's field names the part at fault, such as discord_access.roles:
400 discord_rule_invalid: the server isn't one of this business's, a role isn't in it, or a value is out of range. The message says which.400 discord_role_refused: a role the bot can't give, such as one above the bot's own role or one Discord manages.400 discord_role_warning: a role with moderation powers. Add its id toaccept_powersto give it anyway.400 discord_cancel_day_required: a plan or subscription with Discord access needsbilling.cancel_after_days, so access ends on some day when an invoice goes unpaid.409 discord_kick_missing:on_end: "kick", and the bot hasn't got Kick Members in that server. Sendon_end: "remove_roles", or give the bot the permission.
Where the rule lives:
- Payment links keep their access until the payer starts paying; after that, a change is
409 link_not_editable. - A session made from a checkout gives the checkout's access, so sending
discord_accesswithcheckoutis400 field_not_allowed.
Sessions and the connect URL
A checkout session that gives Discord access answers discord_access and discord_connect_url. The URL is the session's hosted page, where the buyer connects Discord and pays. It's null once a Discord account is connected for the session, and once the session can't be paid any more.
- Buyers pay on Railbed's page: send them to the session's
urlas usual. They connect Discord there before paying. - Your own checkout: send the buyer to
discord_connect_urlto connect, then start the session from your server.
Starting a session
A session with Discord access starts only once its buyer has connected their Discord account:
400 discord_required: no Discord account is connected for this session yet. Send the buyer todiscord_connect_url, then start again. For a session made from a checkout, the buyer connects and pays on the session'surl, because a checkout's buyers connect in their own browsers.409 discord_unavailable: the server can't give access right now, for example the bot was removed from it. Nothing was started. Check the server in the dashboard.409 discord_has_access: that Discord account already has access to this product that doesn't run out.
The Discord access object
One purchase's access: what a buyer got for one payment or one subscription, or what the team gave by hand.
| Field | Type | Description |
|---|---|---|
id | string | The access id, den_… |
object | string | "discord_access" |
livemode | boolean | false for Test mode, true for Live mode |
status | string | Where it stands: see Statuses |
server | object | id (Discord's server id) and name |
roles | array | The roles it gives: id and name |
discord_user | object or null | The Discord account: id and username. null until the buyer connects, and after their details are deleted |
customer | string or null | The customer id, cus_…. null for access given by hand without one, and after the customer's details are deleted |
source | object | What gave it: type (payment, subscription or manual) and id (the payment's pay_… or the subscription's sub_…, null for manual) |
starts_at | integer or null | When the access began, in Unix seconds. null until the payment settles |
ends_at | integer or null | When it ends or ended, in Unix seconds. null for access that doesn't run out, and while a subscription runs |
ended_reason | string or null | Once status is ended: time_up, subscription_ended, never_paid, removed (by the team), erased (the customer's details were deleted) or product_removed. null before |
needs_attention | string or null | Why it needs the business, while status is needs_attention, removed_in_discord or access_not_removed: such as banned, server_limit, needs_join, removed_in_discord, grant_failed, removal_stuck, bot_removed, missing_permission or staff_off. null otherwise. Treat a value you don't know as needing a look |
The object never carries the buyer's Discord sign-in, their picture, their device or IP address.
{
"id": "den_4f9a2c7e1b8d3f6a0c5e",
"object": "discord_access",
"livemode": true,
"status": "has_access",
"server": {
"id": "1180429738155892816",
"name": "Guild Hall"
},
"roles": [
{
"id": "1180431102246014986",
"name": "Member"
}
],
"discord_user": {
"id": "912345678901234567",
"username": "ada.plays"
},
"customer": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
"source": {
"type": "payment",
"id": "pay_Dc4mQ8vT2nXr6KpZw1Lb"
},
"starts_at": 1795510800,
"ends_at": 1798102800,
"ended_reason": null,
"needs_attention": null
}Statuses
| Status | What it means |
|---|---|
waiting_for_payment | The buyer connected Discord and the payment hasn't settled yet |
giving_access | Paid: the bot is giving the roles |
has_access | Discord confirmed the roles |
ending | A subscription that ends at the end of its paid time: the member keeps the roles until then |
needs_attention | The roles can't be given now; needs_attention says why |
removed_in_discord | Someone in the server took a role the bot gave. The bot leaves it off until the team restores or removes the access in the dashboard |
removing_access | The access ended: the bot is taking the roles back |
access_not_removed | The bot couldn't take the roles back; needs_attention says why |
ended | The access is over and the roles are gone, or another purchase still gives them. ended_reason says why |
New statuses may be added. Treat one you don't recognize as not having access.
List Discord servers
GET /v1/discord/servers
Returns the Discord servers this business has connected, newest first, a disconnected one included. Servers aren't per mode, so a Test key and a Live key read the same list.
| Parameter | Description |
|---|---|
limit | 1 to 100, default 20 |
starting_after | The next_cursor of the previous page |
Each server has id (Discord's server id: what discord_access.server takes), object ("discord_server"), name, status (active, needs_attention or disconnected) and problem (bot_removed, missing_permission, kick_missing or staff_off, or null).
curl https://pay.railbed.io/v1/discord/servers \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"{
"object": "list",
"data": [
{
"id": "1180429738155892816",
"object": "discord_server",
"name": "Guild Hall",
"status": "active",
"problem": null
}
],
"has_more": false,
"next_cursor": null
}List Discord access
GET /v1/discord/access
Returns purchases' Discord access in the key's mode, newest first.
| Parameter | Description |
|---|---|
customer | Only this customer's, cus_… |
server | Only this Discord server's, by Discord's server id |
status | Only access with this status |
limit | 1 to 100, default 20 |
starting_after | The next_cursor of the previous page |
curl "https://pay.railbed.io/v1/discord/access?customer=cus_Rk8mW3pZ6tQv1NxLc4Ys&status=has_access" \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"{
"object": "list",
"data": [
{
"id": "den_4f9a2c7e1b8d3f6a0c5e",
"object": "discord_access",
"livemode": true,
"status": "has_access",
"server": {
"id": "1180429738155892816",
"name": "Guild Hall"
},
"roles": [
{
"id": "1180431102246014986",
"name": "Member"
}
],
"discord_user": {
"id": "912345678901234567",
"username": "ada.plays"
},
"customer": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
"source": {
"type": "payment",
"id": "pay_Dc4mQ8vT2nXr6KpZw1Lb"
},
"starts_at": 1795510800,
"ends_at": 1798102800,
"ended_reason": null,
"needs_attention": null
}
],
"has_more": false,
"next_cursor": null
}A customer, server or status in the wrong form is 400 invalid_customer, 400 invalid_server or 400 invalid_status.
Retrieve Discord access
GET /v1/discord/access/:id
Returns one purchase's access. One in the other mode, or another business's, is 404 not_found.
curl https://pay.railbed.io/v1/discord/access/den_4f9a2c7e1b8d3f6a0c5e \
-H "Authorization: Bearer $RAILBED_SECRET_KEY"{
"id": "den_4f9a2c7e1b8d3f6a0c5e",
"object": "discord_access",
"livemode": true,
"status": "has_access",
"server": {
"id": "1180429738155892816",
"name": "Guild Hall"
},
"roles": [
{
"id": "1180431102246014986",
"name": "Member"
}
],
"discord_user": {
"id": "912345678901234567",
"username": "ada.plays"
},
"customer": "cus_Rk8mW3pZ6tQv1NxLc4Ys",
"source": {
"type": "payment",
"id": "pay_Dc4mQ8vT2nXr6KpZw1Lb"
},
"starts_at": 1795510800,
"ends_at": 1798102800,
"ended_reason": null,
"needs_attention": null
}Access
The reads need the customers:read scope, which every secret key has, Read only keys included, and connected AI agents too. Setting discord_access needs the scope of the object it's on, such as checkouts:write. Giving, restoring and removing one member's access by hand is done in the dashboard.