This is a discord bot that lets you sync your Discord server membership with your Discourse users.
This plugin does two things:
Helps you sync membership of your Discord server with your Discourse instance.
Fundamentally, allows you to power a Discord bot using your Discourse server to do stuff to link the two systems.
There are three commands:
To check if the bot is responding, just type “Ping!” and the bot should respond with “ : Pong!” - marvellous, eh? (this is a bit of a meme btw!)
!disckick <min_trust_level: default 2>
Typing this will kick any user that exists on your Discourse but at a Trust Level below your supplied value. The default if you don’t supply a value is 2.
!discsync <clean up: default false, min_visibility: default 0, include automated groups: default false>
This command will attempt to copy over all groups into Roles on Discord which match provided criteria (or defaults if not provided). It will then attempt to populate the roles as per the Group membership on Discourse. It’s a one way sync only. No Discourse data is ever changed.
- a Discord server on which you are Admin
- a Discord App (see below)
- a Discord Bot (see below)
- ssh root access to your Discourse server
- updates to app.yml to
libsodium, a dependency (see below)
- install the plugin
- All users of your Discourse will need to login using Discord OAuth login that will appear on your login page once the plugin is installed.
Go here and create an app:
Hit “New Application”
You will need to create a Bot and it will look something like this (leave it not ‘public’):
You will need to authorise the bot in the browser, see https://discordapp.com/developers/docs/topics/oauth2#bot-authorization-flow
Once the bot is set up, copy the Token. You will need to enter that into Discourse later.
Add this plugin to your app.yml in the same way you normally install a plugin.
This library is required for the
discordrb gem, installed by
plugin.rb, to work.
hooks: before_code: - exec: cmd: - apt-get update - apt-get install -y libsodium-dev
This goes just above where you specify your plugins. The
hooks statement should already exist. You need to add the plugins to the plugin section directly beneath this.
Once in your Discourse admin area, go to Plugin Settings and fill these settings:
You will get the IDs from Discord interface. You will need to activate Developer Mode to allow you to copy these IDs. In Discord, go to your Settings - > Appearance - > ADVANCED and enable Developer Mode:
You can then get ID’s on from the interface, e.g.:
You will also need to fill in the Discord OAuth Settings. The Client ID and Secret are from your very same Discord App.
Rebuild to connect
Once you’ve set up your app.yml and your site settings, go back to your root prompt in linux and type:
./launcher rebuild app
If you’ve set up your Discord and Discourse servers correctly, you should see the bot join the server.
If ever the bot falls over (it will go offline) you will need to do the same thing again to bring it back. Improved independence of the bot from the Discourse core server is a to do. That said, I’ve run a bot in Production for a long while and it’s yet to fall over.
If you have an idea for another command that leverages the link between Discourse and Discord that you believe would be useful to the wider community let me know in the replies and we can look at the potential to implement that. NB this bot is not intended to perform tasks outside the scope of Discourse.