# Discord Sync: sync a Discourse forum with a Discord server

**URL:** <https://meta.discourse.org/t/discord-sync-sync-a-discourse-forum-with-a-discord-server/175864>\
**Category:** Plugin\
**Tags:** unmaintained\
**Created:** [January 12, 2021, 11:47am UTC](https://meta.discourse.org/t/discord-sync-sync-a-discourse-forum-with-a-discord-server/175864 "2021-01-12T11:47:26Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![barreeeiroo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barreeeiroo/32/165264_2.png) [@barreeeiroo](https://meta.discourse.org/u/barreeeiroo)\
**Post date:** [January 12, 2021, 11:47am UTC](https://meta.discourse.org/t/discord-sync-sync-a-discourse-forum-with-a-discord-server/175864/1 "2021-01-12T11:47:26Z")

</div>

> ⚠ 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](https://meta.discourse.org/t/discord-bot-run-one-on-your-discourse-server-keep-things-in-sync/122530) 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.

[https://github.com/barreeeiroo/discourse-discord-sync](https://github.com/barreeeiroo/discourse-discord-sync)

## 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.

- **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

❗ 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](https://meta.discourse.org/t/partially-enable-login-option/175330/4).

### Prerrequisites

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

```plaintext
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](https://meta.discourse.org/t/install-a-plugin/19157) with this repository URL: `https://github.com/barreeeiroo/discourse-discord-sync.git`
2. Follow [this guide](https://meta.discourse.org/t/configuring-discord-login-for-discourse/127129) 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](https://kodul.ar/discord):

> **[Kodular Community](https://community.kodular.io)**
>
> A place for Koders to share and discuss their thoughts

## Acknowledgment

- [**Discourse Bot**](https://meta.discourse.org/t/discord-bot-run-one-on-your-discourse-server-keep-things-in-sync/122530), 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**](https://github.com/angusmcleod/discourse-discord-sync), made by @angus  
An alternative to sync trust levels into Discord roles without the need of any bot.

- [**Login with Discord**](https://meta.discourse.org/t/deprecated-discord-oauth2-plugin/67174), 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**](https://github.com/discordrb/discordrb)  
This plugin relies on the `discordrb` gem, which allows connecting to the Discord API using Ruby.

---

_[View the full topic](https://meta.discourse.org/t/discord-sync-sync-a-discourse-forum-with-a-discord-server/175864)._
