# Discord Bot Construction Kit 🤖

**URL:** https://meta.discourse.org/t/discord-bot-construction-kit/122530
**Category:** Plugin
**Tags:** pavilion
**Created:** [July 10, 2019, 8:29am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530 "2019-07-10T08:29:26Z")
**Posts on this page:** 20
**Page:** 4

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 13, 2020, 8:26am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/67 "2020-11-13T08:26:37Z")

</div>

Great. Btw I will gladly consider any useful _generic_ improvements to this plugin in case you decide to get coding again 😉

---

<div class="post-metadata">

### Author: ![SvenC56](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/svenc56/32/132235_2.png) [@SvenC56](https://meta.discourse.org/u/SvenC56)
#### Post date: [November 15, 2020, 9:40am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/68 "2020-11-15T09:40:56Z")

</div>

Okay let’s start slow. I just submitted my first pull request to this repo 😄.  
[https://github.com/merefield/discourse-discord-bot/pull/3](https://github.com/merefield/discourse-discord-bot/pull/3)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 15, 2020, 9:43am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/69 "2020-11-15T09:43:55Z")

</div>

merged 🙂 thanks!

---

<div class="post-metadata">

### Author: ![Steven\_Copeland](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven_copeland/32/156439_2.png) [@Steven\_Copeland](https://meta.discourse.org/u/Steven_Copeland)
#### Post date: [November 19, 2020, 10:53pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/70 "2020-11-19T22:53:07Z")

</div>

Hey! I’ve been trying to find a plugin that will give users in Discord a role based on the badges they have on their Discourse profile. Is this possible with your plugin? If not, is it even possible? Thanks!

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [November 21, 2020, 8:25am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/71 "2020-11-21T08:25:37Z")

</div>

Not at present but no reason why you couldn’t fork it and add an appropriate command to implement that!

If implemented well I would consider merging a PR. However it might be a little specific for general use because presumably you’d have to maintain some kind of mapping unless the badge names were same as role names? In any case you’d have to filter out most of them? That might get messy for general use. If you find a really clean way to manage that which would work for general users of the plugin let me know.

But fork away, fill your boots!

---

<div class="post-metadata">

### Author: ![anon82467725](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@anon82467725](https://meta.discourse.org/u/anon82467725)
#### Post date: [November 25, 2020, 8:40pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/72 "2020-11-25T20:40:23Z")

</div>

I would definitely like to see if it is possible. That would make me even more interested in this plugin. 😃

---

<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 7, 2021, 12:56am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/73 "2021-01-07T00:56:06Z")

</div>

Just a small question: do we have to manually run `!discsync` every time we want to update roles, or is it automatic?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [January 7, 2021, 9:04am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/74 "2021-01-07T09:04:19Z")

</div>

Unfortunately yes. It might be a nice enhancement to add a ‘repeat in x hours’ parameter (PR welcome or hire me to implement), but as I’ve mentioned before in this Topic, it would be better if someone produced a new plugin using their API and created some scheduled sidekiq jobs to do that. A bot is a fun solution but not the best architecture for scheduled syncing.

---

<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 7, 2021, 9:20am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/75 "2021-01-07T09:20:37Z")

</div>

Oh, thanks anyway. Yeah, we have already thought about a possible alternative…  
We wanted to sync Discourse groups with Discord roles, but it looks like there is no perfect solution that suits.

We are now going to make some kind of bot using webhooks: Discourse will trigger a webhook when an user’s groups is updated (or username change as well) to a custom solution, which will then assign roles in Discord. We will keep using the Discord OAuth choice in order to get guilds, and by creating a custom [Data Explorer](https://meta.discourse.org/t/32566?silent=true) query, we can get through the API those guilds.

It would be something like this:

1. User changes groups or username
2. Webhook to custom solution is triggered
3. This custom solution will call back to [Data Explorer](https://meta.discourse.org/t/32566?silent=true) API to a custom query that returns the guilds from the user
4. With that guild, we call Discord back to update roles

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [January 7, 2021, 9:23am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/76 "2021-01-07T09:23:09Z")

</div>

A proper batch job would be better so you don’t lose data integrity due to one-off event glitches. Both would be perfect.

---

<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, 10:49am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/77 "2021-01-12T10:49:17Z")

</div>

Well, I didn’t go through that way… 😅  
I’ve forked your repo, and made a new plugin that suited our needs:

> **[GitHub - barreeeiroo/discourse-discord-sync: A Discord bot that runs on your Discourse server...](https://github.com/barreeeiroo/discourse-discord-sync)**
>
> A Discord bot that runs on your Discourse server to link the two servers.

It basically syncs all groups with Discord roles, but automatically. When a user is added or removed from a group, it will run a sync job and update their roles according to the public groups. In addition, I’ve added a setting to mark a “verified role”, that will be added to all users who have a Discourse account. And also it supports adding a list of safe roles, which the bot will ignore when syncing users (useful, for example, if wanting to set different admins and mods in the server than in the forum).  
I’ve also added a username-nickname syncer. It can enforce users to have the same server nickname as the forum username.

I’ll open a #Customization > Plugin topic after cleaning up a couple of things, as maybe someone can find it useful.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 18, 2021, 9:30am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/78 "2021-02-18T09:30:40Z")

</div>

@barreeeiroo what was really interesting about your fork was your leveraging of `DiscourseEvents` hooks.

I had assumed that wasn’t possible because the bot is running in a separate thread. But as you’ve discovered, it seems we can act on events and influence the bot. So thanks for that, that’s a really important insight we can develop going forward.

So I’ve started adopting that technique in the main repo, starting with the ability to set some watches on new posts or Topics that willl be announced in the admin channel of Discord.

[https://github.com/merefield/discourse-discord-bot/commit/9f8498c6a56baebb4d21009dff57932b35a46b86](https://github.com/merefield/discourse-discord-bot/commit/9f8498c6a56baebb4d21009dff57932b35a46b86)

The functionality may be of little use as it currently stands but it demostrates the concept for others to leverage.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 20, 2021, 3:51pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/79 "2021-02-20T15:51:07Z")

</div>

OK I’ve developed the plugin a little further now and have POC for two way communication working:

Here are the new settings

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/c/5cf01946d6d8d9b76700eca6226fb92bf0e2a5e3.png)

- You can designate an Announcements Channel on Discord in the plugin settings.

- You can now type into the assigned Discord Announcements Channel and this will post your message to your assigned Discourse Topic in the plugin settings

- You can set up a list of Categories in Discourse to post to the Announcements channel on your Discord if someone Posts there or adds a new Topic (either or both).

[https://github.com/merefield/discourse-discord-bot/commit/a19aa35f6aab2504aa220a1ab3856475f27c795a](https://github.com/merefield/discourse-discord-bot/commit/a19aa35f6aab2504aa220a1ab3856475f27c795a)

In addition I’ve added a new file to manage Discord events supported by the `discordrb` API, with Announcements logic being the first example (feel free to develop new ones and PR if of general use to the community).

I’ve also _removed_ the changes required to app.yml to install `libsodium-dev` as this is now optional having updated the dependencies and not required for the plugin at present (no need to handle voice). This will make installation much simpler.

---

<div class="post-metadata">

### Author: ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)
#### Post date: [November 8, 2021, 4:02am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/80 "2021-11-08T04:02:47Z")

</div>

I followed the installation instructions and everything went smoothly up to the restart. The bot did not join the room, so I checked /logs:

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/2/426b4c0c4b091a525c6d96bce8a34fab4bc87434.png)

Is this referring to the `discord_bot_token`? It’s filled in, and I verified the value. Any clues?

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/8/684064051405c9fb200881c3a278e4e8a08b54aa.png)

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 17, 2021, 5:08pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/81 "2021-12-17T17:08:59Z")

</div>

Mark, apologies, I somehow missed this.

Did you discover the issue?

Can you please update and try the new version and we’ll take it from there

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 17, 2021, 5:12pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/82 "2021-12-17T17:12:52Z")

</div>

A significant update funded by the Discourse team 🎉

[FEATURES: new message auto-copy and history copy command by merefield · Pull Request #4 ·  
merefield/discourse-discord-bot (github.com)](https://github.com/merefield/discourse-discord-bot/pull/4)

1. A new command `!disccopy <number-of-messages> <optional-target-category-name> <optional-target-topic-name>` which allows you to copy Discord message history (in that channel) to your Discourse instance from within Discord chat. This can safely cope with 1,000’s of messages in one go (but for that volume will take time).

2. Automated per message chat copy, by channel to any identically named Category on Discourse: if the channel name matches the Category name, it will copy the message into Discourse if this is set:  
 ![image](https://global.discourse-cdn.com/meta/original/3X/0/8/08cae3dcb28fcf4bf49eda20ca558e3c9d61b59d.png)

3. For any message copied into Discourse from Discord, **the User will now show correctly** if that user has logged into Discourse using the Discord login (So Discord Bot is able to match the user accounts).

4. Localisation support added for a lot of features.

Thanks to @erlend_sh & Discourse team for speccing & sponsoring this work!! 🙏

More bot stuff coming 😉 🤖

---

<div class="post-metadata">

### Author: ![Zup](https://avatars.discourse-cdn.com/v4/letter/z/c37758/32.png) [@Zup](https://meta.discourse.org/u/Zup)
#### Post date: [December 24, 2021, 12:27pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/83 "2021-12-24T12:27:03Z")

</div>

> [@merefield](#):
>
> 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.

If they login with Discourse auth or any auth other than Discord OAuth, would this plugin simply ignore them?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 24, 2021, 12:28pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/84 "2021-12-24T12:28:39Z")

</div>

Doesn’t ignore them, it’s just unable to match the user with the person on the other system. As a result copied messages will appear to be from “system”

---

<div class="post-metadata">

### Author: ![klausagnoletti](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/klausagnoletti/32/237743_2.png) [@klausagnoletti](https://meta.discourse.org/u/klausagnoletti)
#### Post date: [March 10, 2022, 4:10pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/86 "2022-03-10T16:10:15Z")

</div>

Are threads supported?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [March 10, 2022, 4:44pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/87 "2022-03-10T16:44:02Z")

</div>

Not yet, Klaus, but it’s potentially in the pipeline. Waiting for the Ruby API to be updated (blocker) then a backer to add that feature.

[Previous page](https://meta.discourse.org/t/discord-bot-construction-kit/122530.md?page=3)

[Next page](https://meta.discourse.org/t/discord-bot-construction-kit/122530.md?page=5)
