Skip to content

Discord Purchase Roles

Discord Purchase Roles is a Paymenter extension for hosting providers who run a Discord server next to their shop. Customers link their Discord account once through Discord's OAuth2 consent screen. From then on the extension gives them the Discord roles that belong to the products they own, and takes those roles away again when the service ends.

What it does

  • Account linking. Customers get a Discord entry in their account menu. They link, reconnect or unlink their Discord account there and can start a role sync themselves.
  • Product to role mappings. You map a product to a Discord role ID. A product can have several mappings, so it can give several roles, in one or in several Discord servers.
  • Roles follow services. A role is given while the customer has an active service of a mapped product. By default a suspended service keeps the role; you can change that.
  • Removal per mapping. Each mapping decides whether its role is removed when the customer has no qualifying service left.
  • Automatic syncs. A sync is queued when a service is created, deleted, changes status, product or owner, after linking, and after you change a mapping or the relevant settings. A scheduled command queues every linked account again every 15 minutes.
  • Role ledger. The extension records every role it has given in Discord Role Grants. It only removes roles from that ledger. Roles that a member already had, or that somebody gave by hand, are not recorded and not removed.
  • Optional server join. If you switch it on, customers are asked for the extra guilds.join consent and are added to the Discord server of a mapping they qualify for.
  • Cleanup. Unlinking, changing the Discord account and deleting a customer remove all roles from the ledger for that Discord account. Failed removals stay pending and are retried.
  • Admin tools. Four entries in the Extensions navigation group: Discord Settings, Discord Role Mappings, Discord Accounts and Discord Role Grants, with a connection test, manual sync, unlink, adoption of existing roles and cleanup retry.
  • Protected secrets. The bot token, the OAuth2 client secret and the customers' OAuth2 tokens are stored encrypted. Log entries contain the action, the HTTP status or the exception class, never a token.

Requirements

  • Paymenter. The extension was tested with Paymenter 1.5.8 on PHP 8.3.
  • A Discord application with a bot. The bot must be a member of every Discord server you map roles in and needs the Manage Roles permission there. Its own role must be above every role it gives.
  • Outgoing HTTPS from the Paymenter server to discord.com.
  • A running Paymenter queue worker. Automatic syncs are queued jobs.
  • Paymenter's scheduler (php artisan schedule:run every minute) for the 15 minute reconciliation.
  • A cache store that supports locks and is shared by the web server and the queue workers, for example Redis. The extension locks each customer and each Discord account while it changes roles.

Pages

  • Installation: upload, enable, create the Discord application, first-time setup, update, uninstall.
  • Configuration: every field in Discord Settings and Discord Role Mappings.
  • Usage: the admin lists and actions, what the customer sees, and the rules for giving and removing roles.
  • FAQ: common questions and the error messages the extension can show.
  • Changelog: release history.