Skip to content

Installing Discord Purchase Roles

Upload the files

The extension must end up in this folder of your Paymenter installation. The folder name must be exactly DiscordPurchaseRoles.

extensions/Others/DiscordPurchaseRoles/

You can get it there in two ways.

Upload the ZIP in the admin area

  1. In the admin area, open Available Extensions.
  2. Switch to the Ready to Install / Upload tab.
  3. Click Upload Extension, choose the ZIP file and confirm.

Copy the folder by hand

  1. Unpack the ZIP and copy the DiscordPurchaseRoles folder to extensions/Others/DiscordPurchaseRoles/.
  2. Run these commands in the Paymenter root directory:

    composer dump-autoload
    php artisan optimize:clear
    

Install and enable

  1. Open Available Extensions, tab Ready to Install / Upload.
  2. Find Discord Purchase Roles (Jube Hosting) in the list and click Install, then confirm. Paymenter opens the extension's settings page.
  3. Switch on Enabled and save.

The extension's settings page only shows an information text. All settings are in the admin lists described below.

Installing and enabling both run the extension's migrations, which create four tables:

Table Content
ext_discord_settings One row with the bot token, OAuth2 credentials, default server and options
ext_discord_role_mappings Product to role mappings
ext_discord_accounts One linked Discord account per customer
ext_discord_role_grants The ledger of roles the extension has given

Once the extension is enabled:

  • the admin area has four new entries in the Extensions navigation group: Discord Settings, Discord Role Mappings, Discord Accounts and Discord Role Grants,
  • customers see a Discord entry in their account menu, which opens /account/discord,
  • the scheduled command discord:roles:sync runs every 15 minutes.

Prepare Discord

You need one Discord application that has a bot. The same application is used for the bot and for the customer login (OAuth2).

  1. Create an application in the Discord Developer Portal and add a bot to it.
  2. On the Bot page, create the bot token (Reset Token) and copy it.
  3. On the OAuth2 page, copy the Client ID and the Client Secret.
  4. On the OAuth2 page, add this redirect URI, with the address your customers use to reach Paymenter:

    https://your-paymenter-address/account/discord/callback
    

    The exact URL for your installation is shown in the help text below the OAuth2 client secret field in Discord Settings.

  5. Invite the bot to your Discord server and give it the Manage Roles permission. If you want to use the optional server join, it also needs Create Instant Invite.

  6. In the server's role list, move the bot's role above every role the extension should give. Discord rejects role changes for roles at or above the bot's highest role.
  7. Copy the server ID (right click the server in Discord, Copy Server ID) and the ID of each role you want to map (Server Settings, Roles, right click the role, Copy Role ID). Both menu entries need Discord's developer mode.

The extension only uses Discord's REST API. It reads the bot user, reads the server, reads a member, adds and removes a member's role and, with the server join option, adds a member to the server.

For linking, customers are asked for the identify scope. With the server join option switched on, they are asked for identify and guilds.join. No other scope is requested.

Warning

Do not map roles that carry administrator or moderation permissions. Anyone who buys the mapped product and links a Discord account gets the role.

First-time setup

  1. Open Discord Settings in the admin area. Enter Bot token, Default server (guild) ID, OAuth2 client ID and OAuth2 client secret, choose While a service is suspended and save. See Configuration.
  2. Click Test connection at the top of the page. It uses the saved values. The expected result is Bot "<name>" is reachable. without a remark about the server.
  3. Open Discord Role Mappings, click New Discord role mapping and create one mapping per product and role. See Configuration.
  4. Make sure a queue worker and Paymenter's scheduler are running. Paymenter uses the database queue connection.
  5. Check that your cache store supports locks and is shared between the web server and the queue worker. Paymenter's example .env uses CACHE_STORE=redis, which does.
  6. Test with your own account: open Discord in the account menu, click Link Discord account, approve the request in Discord and check that the role arrives.

Note

Until all four of bot token, default server ID, client ID and client secret are saved, the customer page shows "Discord is not configured yet. Please contact support." and has no link button.

The sync and cleanup jobs have a timeout of 120 seconds. Set retry_after of your queue connection to more than that, so a job that is still running is not started a second time.

Updating

  1. Upload the new ZIP with Upload Extension as described above. Paymenter replaces the extensions/Others/DiscordPurchaseRoles folder and calls the extension's upgrade step, which runs any new migrations.
  2. If you replace the folder by hand instead, disable and re-enable the extension afterwards. Enabling runs any new migrations. You can also run them directly:

    php artisan migrate --path=extensions/Others/DiscordPurchaseRoles/database/migrations --force
    
  3. Restart the queue workers so they load the new code:

    php artisan queue:restart
    

Links, tokens, settings and mappings are kept.

Updating from 1.0.x to 1.1.0

Back up the database first. The 1.1.0 migration adds the ext_discord_role_grants table, the server override on mappings and the server join option, which is off after the update. Existing mappings keep using the default server.

Version 1.0.x did not record which roles it gave. After the update, the ledger is empty, so roles that 1.0.x gave are treated like roles given by hand: the extension does not remove them. If you want the extension to manage them, use Adopt existing mapped roles on the customer's row in Discord Accounts. See Usage.

Warning

Do not go back to 1.0.x after you have created more than one mapping for a product. The older version expects one role per product, and the migration's rollback does not restore that limit.

Disabling

Switch off Enabled on the extension's settings page and save. The customer page, the admin lists, the automatic syncs and the scheduled command stop. All four tables and the roles in Discord stay as they are.

Uninstalling

  1. Open the extension's settings page in the admin area.
  2. Click Uninstall Extension and confirm.

Warning

Uninstalling drops all four tables, including the ledger of given roles and any pending cleanup. It does not remove any role in Discord. If the roles should be removed, unlink the accounts first and wait until Discord Role Grants is empty.