# 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:** 5

<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 12, 2022, 7:33am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/88 "2022-03-12T07:33:34Z")

</div>

Allright. That’s a bit of a bummer since I just enforced threads in the support chans of our Discord to get a better overview of support cases. And I am not sure it actually gives that - but luckily there’s other advantages.

Do you have an ETA on the API and an idea of what it would cost to back the feature?

Thanks!

/k

---

<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 12, 2022, 12:30pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/89 "2022-03-12T12:30:47Z")

</div>

I did chase recently and it’s been in development for some time. I’ll chase again and revert, but be warned, the last time they told me “it’ll be done when it’s done” … the problem with open source is often a lack of a good way of directing appropriate levels of community funding (or lack thereof) to assist with focus and prioritisation … we’ll see …

From my end I’d have to see the final implementation to estimate the effort.

The challenge might be that whilst it’s straightforward to copy across messages, keeping Threads in sync with Topics may require some kind of mapping maintained in Discourse, e.g. a custom field or table that maps Discord Threads to Discourse Topics, so when a new message gets added to a Thread you know where to put it in Discourse.

Can you elaborate on exactly the functionality/behaviour you are seeking?

---

<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 13, 2022, 3:38pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/90 "2022-03-13T15:38:47Z")

</div>

Yeah that sucks to be depending on something you can’t influence.

My idea is very inspired on the article and the discoussion on the Discourse blog on how well Discord and Discourse supplement each other. When we started our Discord server almost two months ago we didn’t really know how it would evolve and how it would affect our existing (but barely configured) Discourse forum but it looks like people still use it as well as our Discord for asking technical support questions (I am with the FOSS project CrowdSec). So basically I completely buy in on the idea to use Discourse as a more long term memory and sync Discord threads to Discourse under topics matching Discord channels (and vice versa). The way I see it, it can be done much more effectively (e.g. automated) by using threads.

As I said I recently enforced threads on Discord which means that it’s not always very easy to get an overview of threads for those of our developers that are assigned to user support. So I want to use the sync to Discourse also as a good way for them to keep updated on questions to answer whilst not being sucked too much into the Discord chitter-chatter.

Does that makes sense? And is there some other way to achieve this on a shorter time frame maybe?

---

<div class="post-metadata">

### Author: ![FerrariFlunker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ferrariflunker/32/258011_2.png) [@FerrariFlunker](https://meta.discourse.org/u/FerrariFlunker)
#### Post date: [March 20, 2022, 9:00pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/91 "2022-03-20T21:00:32Z")

</div>

Hi @merefield !

I’m reaching out to you here because I don’t think my github Issue was seen, and I’m thinking this is the next best place.

![image](https://global.discourse-cdn.com/meta/original/3X/7/0/70c71e5b1ebb57ac2628a406466cabb8167b9e3a.png)

We’ve been getting an error that we’ve tracked down to the discord bot plugin. The above image shows the inspect element error, but any user who sends a PM also gets a “500 Error” visual when their PM is sent. The PM is still sent successfully, but this error makes it seem otherwise. After disabling the plugin, the issue no longer exists.

I’m pretty sure the issue is coming from /lib/discourse\_event\_handlers.rb. I’m assuming that a PM is triggering the post\_created DiscourseEvent which makes it try to access the post’s category via posted\_category = post.topic.category.id, which causes the error.

I hope this helps and I hope this can be resolved soon. 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: [March 20, 2022, 9:05pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/92 "2022-03-20T21:05:37Z")

</div>

Thanks for the report. Sounds about right. Might get chance to look at it this week …

---

<div class="post-metadata">

### Author: ![FerrariFlunker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ferrariflunker/32/258011_2.png) [@FerrariFlunker](https://meta.discourse.org/u/FerrariFlunker)
#### Post date: [March 20, 2022, 9:24pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/93 "2022-03-20T21:24:23Z")

</div>

Fantastic, thank you! We’ll keep an eye out for the update. 👍

---

<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 26, 2022, 7:28am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/94 "2022-03-26T07:28:16Z")

</div>

Heads up that I’m drowning in client work atm so this may not get looked at for a little while.

In the meantime PR accepted.

In general I would welcome more community contribution to the free plugins.

---

<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: [April 11, 2022, 5:48pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/95 "2022-04-11T17:48:19Z")

</div>

Things are preeeetty busy for me atm, but I’ve pushed what I believe is a fix:

[FIX: exclude private messages from bot event considerations · merefield/discourse-discord-bot@82b2109 (github.com)](https://github.com/merefield/discourse-discord-bot/commit/82b210980c2e0ef17a1ea6d310442c62b3454973)

Seems to work now and the dreaded 500 on PM’s is gone …

---

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [July 8, 2022, 2:03pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/96 "2022-07-08T14:03:23Z")

</div>

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

Oh, that’s wonderful and replaces [Discord Chat](https://meta.discourse.org/t/set-up-discord-notifications-using-the-discourse-chat-integration-plugin/66600)!

¿It has supposed to read slug names on Discourse or just titles?

---

<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: [July 8, 2022, 2:28pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/97 "2022-07-08T14:28:56Z")

</div>

Discord does not manage by slugs in the same way, so iirc it is titles.

---

<div class="post-metadata">

### Author: ![forgondolin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/forgondolin/32/266222_2.png) [@forgondolin](https://meta.discourse.org/u/forgondolin)
#### Post date: [July 9, 2022, 2:28pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/98 "2022-07-09T14:28:18Z")

</div>

Hello, I don’t know if this was questioned before but, the OAuth credentials must be the same as the app? Cause right now we are using another discord sync integration and the OAuth fields are already filled. 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: [July 9, 2022, 2:37pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/99 "2022-07-09T14:37:56Z")

</div>

This plugin is compatible with the official social login solution in core. The bot needs a token from an authorised Discord app. The social login allows the plugin to identify the same user across the two platforms.

---

<div class="post-metadata">

### Author: ![forgondolin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/forgondolin/32/266222_2.png) [@forgondolin](https://meta.discourse.org/u/forgondolin)
#### Post date: [July 9, 2022, 2:42pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/100 "2022-07-09T14:42:16Z")

</div>

thanks for the answer! I’ll debug a little bit more to see what I’m missing on the setup.

---

<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: [July 9, 2022, 2:49pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/101 "2022-07-09T14:49:09Z")

</div>

I don’t think it needs to be the same discord app but try it!

---

<div class="post-metadata">

### Author: ![Skip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/skip/32/266443_2.png) [@Skip](https://meta.discourse.org/u/Skip)
#### Post date: [July 11, 2022, 1:03pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/102 "2022-07-11T13:03:16Z")

</div>

Hello here!  
Searching the forum for a way to give the Discourse users a different Trust Level based on a Discord account brought me here.

We already have a pretty active community on Discord and brought in Discourse lately for more organized discussions.

I am looking for a solution that goes like this. A member that logins with their Discord account and has a specific role on Discord automatically receives a Trust Level 1 on Discourse.

Would this Bot Kit be the right starting point for such an implementation?

Thank you

---

<div class="post-metadata">

### Author: ![StonkGodCapital](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stonkgodcapital/32/242643_2.png) [@StonkGodCapital](https://meta.discourse.org/u/StonkGodCapital)
#### Post date: [July 15, 2022, 4:35pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/103 "2022-07-15T16:35:01Z")

</div>

This bot afaik is “one-way” from Discourse to Discord. There aren’t any functions that are the opposite that are built.

Personally I think you’d find it a bit easier to accomplish this with outside code that is watching the user events webhook of your discourse install.

> Webhook event out → Grab discord user ID from Discourse database (requires using Discord authentication) → Grab roles using discord.js, .py, etc. → Assign role with Discourse API request

In order to get the Discord ID you need to use the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin and create the following query:

```plaintext
-- [params]
-- string :user
SELECT u.username, u.id, a.user_id, a.provider_name, a.provider_uid
FROM users u
JOIN user_associated_accounts a on a.user_id = u.id
WHERE u.username = :user

```

You can then look up the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin documentation and hit that query with an API request to get the ID.

Hope this helps somewhat.

---

<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: [July 16, 2022, 4:46am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/104 "2022-07-16T04:46:10Z")

</div>

> [@StonkGodCapital](#):
>
> This bot afaik is “one-way” from Discourse to Discord. There aren’t any functions that are the opposite that are built.

Whilst this is true for role sync, this is otherwise not correct.

From the OP:

> [@merefield](#):
>
> - Provides some two-way auto posting of content that meet some criteria.
> - Command to copy messages ad hoc to Discourse

So plenty of Discord → Discourse behaviour and far from just a ‘role sync’ bot.

As ever PR welcome for any generally useful additional functionality. It would be good to have some additions from the community. 👀

---

<div class="post-metadata">

### Author: ![Kenechukwu\_Eze](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kenechukwu_eze/32/291369_2.png) [@Kenechukwu\_Eze](https://meta.discourse.org/u/Kenechukwu_Eze)
#### Post date: [January 31, 2023, 11:52am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/105 "2023-01-31T11:52:47Z")

</div>

Thank you for this post @merefield

Could I get your discord? I would like to ask you some questions if that’s okay.

---

<div class="post-metadata">

### Author: ![AquaL1te](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/aqual1te/32/201966_2.png) [@AquaL1te](https://meta.discourse.org/u/AquaL1te)
#### Post date: [January 31, 2023, 12:21pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/106 "2023-01-31T12:21:06Z")

</div>

To keep knowledge open and indexed for everyone it’s probably best to ask the questions here. Discord is a black hole for information. Stuff goes in and is then never found again 🙂 And otherwise, we also have chat here on Discourse.

---

<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 31, 2023, 5:03pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/107 "2023-01-31T17:03:56Z")

</div>

Hi Kene, if it’s not of a commercial nature, would appreciate if you could ask your questions here so that the community might benefit from (or even answer) them

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

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