Discord integration: login, roles after purchase and webhooks

VulCode, a software house from Cracow, Poland, ties Discord into the website, store and panel of game servers and communities. A player signs in with a Discord account, after a paid purchase a bot gives them a role, and when it expires the bot takes it away. Orders go to channels by webhook, and everything stays within Discord's API limits. The Discord integration costs from PLN 999 (about EUR 220) and usually takes 2-3 days, and the free quote comes back within an hour.

  1. 01

    OAuth2 with the identify scope gives the player profile with no password on your site.

  2. 02

    A bot with MANAGE_ROLES grants and removes roles after store events.

  1. 01

    We build and run Discord bots for tickets, welcomes, email verification and role management, and send all webhook traffic through a queue that respects Discord's limits. They are in our integrations portfolio.

  2. 02

    We cover bots with commands and server automation separately on the Discord bots page. This page is about connecting Discord with your site, store or panel.

Login, joining the server and a role

An OAuth2 run with the identify and guilds.join scopes. Hover a step to highlight it.

PlayerYour siteDiscord OAuth2Bot on the server
Player → Your site
clicks "Sign in with Discord"
Your site → Discord OAuth2
redirect with scopes and a state parameter
Discord OAuth2 → Your site
an authorisation code and the same state
Your site → Discord OAuth2
exchange the code for a token
Your site → Bot on the server
add the player to the server with a role

player token and bot token

Bot on the server → Player
the player is on the server with a rank
The state parameter
Discord does not require it but strongly recommends it. Without it, login is open to CSRF, so we always check it.
The bot already on the server
Only a bot of the same application that is on the server and may create invites can add a player.

Discord limits that decide stability

From the Rate Limits docs. Breaching the last one means a temporary block of the whole IP.

JSON application/json
[
                {
                "Limit": "Per route","Value": "varies, in X-RateLimit-* headers","What we do": "We read the headers and group requests by bucket."
                },
              
                {
                "Limit": "Global","Value": "50 requests per second per bot","What we do": "A queue with a steady pace, also for bulk role grants."
                },
              
                {
                "Limit": "Invalid requests","Value": "10,000 responses of 401, 403 and 429 per 10 minutes","What we do": "We never retry 401 and 403, and retry 429 only after waiting."
                },
              
                {
                "Limit": "A webhook returning 404","Value": "must not be used again","What we do": "We remove it from config and alert support."
                },
              
                {
                "Limit": "Message","Value": "up to 10 embeds, 6,000 characters in total","What we do": "We split long reports into several messages."
                }
              ]
The same record in the interface

Limit 5

  1. Per route Value varies, in X-RateLimit-* headers What we do We read the headers and group requests by bucket.
  2. Global Value 50 requests per second per bot What we do A queue with a steady pace, also for bulk role grants.
  3. Invalid requests Value 10,000 responses of 401, 403 and 429 per 10 minutes What we do We never retry 401 and 403, and retry 429 only after waiting.
  4. A webhook returning 404 Value must not be used again What we do We remove it from config and alert support.
  5. Message Value up to 10 embeds, 6,000 characters in total What we do We split long reports into several messages.

What flows between your system and Discord

A typical set for a game server or community with paid ranks.

Site, store, panelDiscord

Player profile

Discord login

Rank role

a paid purchase

Role removal

expiry or a refund

Channel notification

an order, a ticket, an outage

via webhook, no bot needed

Linked role data

a change in level or playtime

Three ways to grant roles

The choice depends on whether the role comes from a purchase or from player data.

The bot grants the roleLinked rolesBy hand
Works right after purchase YesPartlyNo
The player must link an account only at first loginyes, through a verification pageno
Removal on expiry YesPartlyNo
Constraints the bot's role must sit above the granted onemax. 5 data fields per appmoderators' time

With linked roles the server sets the condition, e.g. level 10 or more, and the app only updates player data through the API.

06

What we watch out for with Discord

The most common reasons a role does not arrive or the bot gets blocked.

  1. 01

    Permissions

    Role hierarchy

    A bot grants only roles below its own highest one. We set the role order with you at launch.

  2. 02

    Minimal scopes

    We ask the player only for the scopes we use. Every extra one puts people off signing in.

  3. 03

    A queue that respects 429

    Bulk operations, such as removing roles at season end, go at a pace Discord accepts.

  4. 04

    Daily role reconciliation

    We compare server roles with purchases, so a role granted by hand or lost does not live on.

A webhook or a bot

Not every Discord integration needs a bot.

A webhook is enough

  • You only want channel notifications: orders, tickets, statuses.
  • You need no roles or commands.

A webhook URL in config and clear embeds. The quickest rollout.

A bot is needed

  • Roles must depend on purchases or the player account.
  • You want to add players to the server at login.
  • Players should use commands.

A Discord app with a bot on the server and an operation queue on your side.

Discord bots

Example rollout: VIP ranks in a server item shop

Step by step.

Server
A game server with an item shop and a Discord community
Today
A moderator grants ranks by hand from a payment screenshot
Goal
The rank on Discord and in game right after payment
  1. 1

    Discord login

    The player signs in to the shop with Discord, so we know whom to grant the role.

  2. 2

    Payment and role

    A confirmed payment adds the VIP role and the in-game rank from the same event.

  3. 3

    Expiry

    A daily job removes expired roles at a pace within the limits.

  4. 4

    Notifications

    Each purchase goes via webhook to the admin channel with the amount and rank.

Moderators stop granting ranks by hand, and the player gets the rank seconds after paying.

Common questions about Discord integration

Click a question to see the answer.

How much does the Discord integration cost?
The Discord integration costs from PLN 999 (about EUR 220). The figure grows with the number of systems, data directions and exceptions to handle. A typical integration takes 2-3 days, and the free quote comes back within an hour. We quote it under our API and integrations service.
How long does it take?
Usually 2-3 days. The exact dated schedule comes with the free quote, and if anything is going to move, you know in advance.
Must the player already be on the server?
No. With the guilds.join scope the bot can add them to the server at login, with the role straight away.
What if the player leaves the server and comes back?
The daily reconciliation or the join event restores the role if the purchase is still valid.
Can you connect Discord to a hosting panel?
Yes. Discord login and service notifications work the same way in a client panel, e.g. with Pterodactyl.
Will the Discord integration code be mine?
Yes. Once the work is accepted and paid in full, the economic copyright in the code passes to you. You have access to the repository from the first day, and after acceptance you get it with run instructions. Open source libraries keep their own licences.
How do you check the Discord integration before launch?
On a test Discord server with a test bot, before anything reaches your server. We run real scenarios, including errors, cancellations and returns, and only then switch the integration on in production.
What if the Discord integration stops working?
The integration retries failed operations by itself and logs every one, and when the problem does not go away you get a notification. We fix bugs that come from our work under warranty, and you get 90 days of support included after launch.
What if Discord changes its API?
Discord announces changes in advance. We follow those notices and adapt the integration under a maintenance plan or as a separate short order, before the old version stops working.

Sources

Technical details come from the Discord developer documentation.

Describe your project.

A free quote comes back within an hour during working hours.