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:

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.

FieldTypeDescription
serverobjectThe server: id (Discord's server id) and name
rolesarrayThe roles a purchase gives, one to five: each id (Discord's role id) and name
plan_rolesobject or nullA pricing table's roles for each plan, keyed by plan id, when they differ by plan. null otherwise
duration_daysinteger or nullHow 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_endstringWhat happens when access ends: remove_roles, or kick to also remove the member from the server
remindersbooleanWhether 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
A session with Discord access
{
  "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"
}
201 Created

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:

FieldTypeDescription
serverstringRequired. The Discord server id, from List Discord servers
rolesarray of stringsRequired. One to five Discord role ids in that server
plan_rolesobjectA pricing table only: role ids for each plan id, for plans that give other roles
duration_daysinteger or nullA 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_endstringremove_roles (the default) or kick. kick needs the bot to have Kick Members in that server
remindersbooleanDefault true
accept_powersarray of stringsRole 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
holdersstringSent 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
    }
  }'

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 to accept_powers to give it anyway.
  • 400 discord_cancel_day_required: a plan or subscription with Discord access needs billing.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. Send on_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_access with checkout is 400 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 url as usual. They connect Discord there before paying.
  • Your own checkout: send the buyer to discord_connect_url to 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 to discord_connect_url, then start again. For a session made from a checkout, the buyer connects and pays on the session's url, 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.

FieldTypeDescription
idstringThe access id, den_…
objectstring"discord_access"
livemodebooleanfalse for Test mode, true for Live mode
statusstringWhere it stands: see Statuses
serverobjectid (Discord's server id) and name
rolesarrayThe roles it gives: id and name
discord_userobject or nullThe Discord account: id and username. null until the buyer connects, and after their details are deleted
customerstring or nullThe customer id, cus_…. null for access given by hand without one, and after the customer's details are deleted
sourceobjectWhat gave it: type (payment, subscription or manual) and id (the payment's pay_… or the subscription's sub_…, null for manual)
starts_atinteger or nullWhen the access began, in Unix seconds. null until the payment settles
ends_atinteger or nullWhen it ends or ended, in Unix seconds. null for access that doesn't run out, and while a subscription runs
ended_reasonstring or nullOnce 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_attentionstring or nullWhy 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.

Discord access
{
  "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
}
200 OK

Statuses

StatusWhat it means
waiting_for_paymentThe buyer connected Discord and the payment hasn't settled yet
giving_accessPaid: the bot is giving the roles
has_accessDiscord confirmed the roles
endingA subscription that ends at the end of its paid time: the member keeps the roles until then
needs_attentionThe roles can't be given now; needs_attention says why
removed_in_discordSomeone 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_accessThe access ended: the bot is taking the roles back
access_not_removedThe bot couldn't take the roles back; needs_attention says why
endedThe 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.

ParameterDescription
limit1 to 100, default 20
starting_afterThe 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"
Response
{
  "object": "list",
  "data": [
    {
      "id": "1180429738155892816",
      "object": "discord_server",
      "name": "Guild Hall",
      "status": "active",
      "problem": null
    }
  ],
  "has_more": false,
  "next_cursor": null
}
200 OK

List Discord access

GET /v1/discord/access

Returns purchases' Discord access in the key's mode, newest first.

ParameterDescription
customerOnly this customer's, cus_…
serverOnly this Discord server's, by Discord's server id
statusOnly access with this status
limit1 to 100, default 20
starting_afterThe 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"
Response
{
  "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
}
200 OK

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"
Response
{
  "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
}
200 OK

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.

Updated · This page as Markdown