Discord Sync: sync a Discourse forum with a Discord server

:warning: This plugin is automatic; it does not have any command. If you are looking for a generic discord bot framework please check @merefield’s bot construction kit here on which this plugin was based.

Discord Sync Sync a Discourse forum with a Discord server :discourse:

This plugin allows syncing certain user-related stuff between a Discourse forum instance and a Discord server. It will create a Discord Bot to handle all permissions and trigger with some actions in the server.

Features

  • Sync Discourse groups to Discord roles
    It will automatically manage roles in the Discord server based in the groups that a user has access in Discourse.

    • Verified Role
      You can add a “verified role” that will be granted to all Discord users who have linked a Discord account.

    • Safe Roles
      As this plugin will force having the same roles in Discord than groups in Discourse, you can set a list of roles that the bot will ignore and you can manually manage in the Discord server

  • Sync Discourse username to Discord nickname
    If you want to recognize users by their forum username, you can force them to have the same Discord server nickname as the username they have in Discourse

Triggers

The plugin will run a complete Discourse-to-Discord sync (nickname and roles) in the following cases:

  • Discourse
    • User is added to a group
    • User is removed from a group
    • User profile is updated
      Intended for username-nickname syncing
    • User is authenticated
      It will only run if the auth provider is Discord, to make sure a first sync is executed just right after linking accounts
  • Discord
    • User joins a Discord server
      It will search in the database for an user with the given Discord ID, and then run the sync job

Installation

:exclamation: This plugin depends on Discord OAuth2 to identify and link Discourse-Discord accounts. If you don’t want to allow users to login with Discord, but you wish to keep linking account, check the solution to this topic.

Prerrequisites

This plugin requires libsodium (required by the Discord Ruby gem). To install it, modify your .yml file and add the following code:

hooks:
    before_code:
       - exec:
              cmd:
                - apt-get update
                - apt-get install -y libsodium-dev

Installation steps

  1. Follow the standard guide at How to install a plugin with this repository URL: https://github.com/barreeeiroo/discourse-discord-sync.git
  2. Follow this guide to set up Login with Discord in your Discourse instance.
  3. In the Discord Developer portal, go to Bot, and add it to your server. Make sure you grant him the highest possible role.
  4. In Discourse, in Plugin Settings, set discord sync token with the Bot token that appears in the previous step.

Configuration options

  • discord sync enabled: Whether or not to enable the integration
  • discord sync token: Bot token from Discord
  • discord sync prefix: Prefix for commands (just !ping by now)
  • discord sync admin channel id: Channel to post logging messages (nick changes, role changes)
  • discord sync username: If true, it will sync all Discord server nicknames to their Discourse username
  • discord sync verified role: Role to add to all users who have a Discourse account
  • discord sync safe roles: List of roles that bot will ignore and will mark as manually granted in Discord

How To

To link accounts, if you allow users to authenticate with Discord, they can just use that provider. If not, they will have to their Account Preferences, scroll down to Associated Accounts and hit Connect in the Discord row.

Live Demo

We are currently using this plugin in our Discourse instance at Kodular Community, with the Discord server at kodul.ar/discord:

Acknowledgment

  • Discourse Bot, made by @merefield
    Thanks a lot to Robert for providing the skeleton of this plugin. It has certainly helped to set up the base of this entire plugin, allowing to run a Discord bot in a Discourse instance (and kudos for his trick on getting libsodium installed!).

  • Discourse Discord Sync, made by @angus
    An alternative to sync trust levels into Discord roles without the need of any bot.

  • Login with Discord, made by Discourse team
    This plugin wouldn’t be possible without the Discord OAuth2 integration (formerly a plugin), to link both Discourse and Discord accounts.

  • discordrb
    This plugin relies on the discordrb gem, which allows connecting to the Discord API using Ruby.

29 Likes

This is really cool! I’m more of a Telegram fan myself, but Discord is great too! I feel like Telegram would pair well with Discourse, both being well known open-source projects focused on communication.

That would be cool if this had a cross-posting feature. If someone said something in the Discord chat, it would create a reply in a specific Discord thread known as the “chat room thread”. Thus giving your Discourse website an SEO boost because of all the new content within the chat thread.

4 Likes

I also like Telegram a lot, and we were using it with a public chat group. But a few days ago we switched to Discord, because we had over 1k members and it’s quite hard to moderate such a large group. It was easy to do it with Discord with their role system.

4 Likes

Nice work :slight_smile:

In addition to @merefield’s Discord Bot, there’s also a pure OAuth2 (bot free) Discord role <> Discourse group sync plugin (e.g. sync trust level 3 with a Discord role) here

https://github.com/angusmcleod/discourse-discord-sync

5 Likes

This syncs Discourse -> Discord. However, we rely more on our Discord roles than Discourse groups for identification of stakeholder types, so it would be great if this plugin could also do a Discord -> Discourse sync, i.e. add Discourse users to groups based on their Discord roles, add badges to Discourse users based on their Discord roles, change the Discourse username to match the Discord username (not the other way around), etc.

1 Like

Would it be possible for you to make this so that it syncs in reverse? i.e. sync roles from Discord into Discourse groups, nicknames, etc.

We manage roles and such from Discord and would rather push them to Discourse.

2 Likes

If you find anything like this please let me know.

This looks really cool. The only thing is, how does it match the group on Discord from Discourse? Is it purely by name? If so, could you make it to where we define what group goes to what role by using the role ID from Discord? If not that solution, do you think you could add a role whitelist? I have only a few roles that have groups on Discourse but utilize many roles on Discord.

1 Like

This particular functionality is so important to us, since we manage all of our roles via Discord. It would be nice to have a way to sync up the groups from Discord to Discourse. Even if they’re only “synced” via name and permissions, etc. are configured after the fact.

@barreeeiroo : do you have any plans for something like this? or have any advice on where to go from here? The manual management of roles via “Safe Roles” is almost good enough. I have roles that have spaces in them and therefore cannot add these into the Safe Roles field. Instead of manually updating all of my roles in discord and adding them without spaces is there another route I can go with?

It would be so nice to have the groups from discord “pushed” to the discourse groups instead, if possible.

Thanks for your work on this plugin!

Edit: The proposal to use Role IDs instead of names would solve a lot of issues on my end for sure.

1 Like

I’m still having issues setting this up. For roles on Discord is it looking for an ID or name? Also, instead of a “protected roles” could you add it so I can synchronize only specific roles?

I don’t know ruby otherwise I’d offer up my assistance. I’ll probably learn the basics or just implement something via the API in Java.

I found my issue, had the name of the admin channel instead of its id. Now I just gotta do some permission/role checking to see why nothing actually happens

1 Like

I just wanted to mention: I built the inverse of this plugin, which syncs discord roles to discourse groups: Sync your Discord roles with your Discourse groups! - YouTube

5 Likes

Is there any wat that you can sync the discord roles with discourse, instead of sync discourse roles with discord?

That’s the point of this plugin? Is it broken? Also take a look at my bot plugin linked in the OP which performs discourse → discord (albeit using bot command)

2 Likes

All plugins here, gives you the roles you have on discourse to your discord account. It doesn’t gives you, your discord roles on your discourse account.

That’s the opposite of your original question?

@spirobel ’s plugin does that I believe?

2 Likes

No, it does example if you have “Community Moderator” in Discourse, it will change your discord role.
But if you have “Community Moderator” in Discord, it won’t change your role in Discourse

2 Likes

I think you may have missed what I was referring to: Discord Sync: sync a Discourse forum with a Discord server - #17 by spirobel

Over to you @spirobel

4 Likes

I missed that, his plugin is a custom made plugin for 400 usd

1 Like

is he actually selling that for 400$? that’s ridiculous.

1 Like