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

<div class="post-metadata">

### Author: ![Zavan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zavan/32/184367_2.png) [@Zavan](https://meta.discourse.org/u/Zavan)
#### Post date: [June 18, 2020, 1:01pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/47 "2020-06-18T13:01:43Z")

</div>

I’d be happy to invite you into my instance? I don’t know if your plugin logs anywhere, would be able to send you that if it helps?

EDIT: When you authorised the bot, what permissions did you allocate it 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: [June 18, 2020, 5:17pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/48 "2020-06-18T17:17:36Z")

</div>

The bot needs Administrator:

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

You need to grant permissions via the browser as described here (and in the OP):

> **[OAuth2 - Documentation - Discord](https://docs.discord.com/developers/topics/oauth2)**

something like: `https://discord.com/api/oauth2/authorize?client_id=YOURCLIENTID&scope=bot&permissions=8`

Your issue is almost certainly Discord side since the Discourse bot server seems to be running (you have shown this with the `Ping!` command), so Discourse logs will be irrelevant.

I’ve just retested this plugin on the latest Discourse version and everything is working (I updated a couple of gems to a more modern version to ensure compatibility with other plugins but this is irrelevant to your issue).

---

<div class="post-metadata">

### Author: ![Zavan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zavan/32/184367_2.png) [@Zavan](https://meta.discourse.org/u/Zavan)
#### Post date: [June 18, 2020, 5:37pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/49 "2020-06-18T17:37:40Z")

</div>

Yep, so I’ve reinvited it a couple of times with no change. It is an admin, it has the bot scope. I am the person inviting it to the discord, I’m the owner of the discord server. It just doesn’t recognise me and returns “You don’t have permission to execute command discsync!”

I’m bamboozled, unfortunately!

---

<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: [June 18, 2020, 6:00pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/50 "2020-06-18T18:00:23Z")

</div>

Did you set these up in Discourse settings?:

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/0/605476779c75a7f24587656a7d46650c195b70b7.png)

---

<div class="post-metadata">

### Author: ![Zavan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zavan/32/184367_2.png) [@Zavan](https://meta.discourse.org/u/Zavan)
#### Post date: [June 19, 2020, 4:35pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/51 "2020-06-19T16:35:11Z")

</div>

Huzzah! It seems I managed to malform the Admin Group ID somehow! Looks like my copy/paste job may have missed a number…

So as a follow on question, I’m now trying to assign people colours in Discord based on their trust level in Discourse. To get trust levels to copy across, I reckon the command should be:

!discsync false, 0, true

Is this correct? It returns the following for me:

 ![20200619_210503](https://global.discourse-cdn.com/meta/original/3X/f/8/f8c64b0ab7599730c78a99d7c1af16c279c67f13.jpeg)

EDIT: The same is returned if I run the command without commas, i.e.:

!discsync false 0 true

---

<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: [June 20, 2020, 11:34am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/52 "2020-06-20T11:34:51Z")

</div>

Increase your Visibility Level. The standard automated Groups default to Visibility 1 (“Logged on users”), so if this value is zero you exclude the default automated Groups:

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

Zero will only include Groups visible to everyone including anonymous.

---

<div class="post-metadata">

### Author: ![Zavan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zavan/32/184367_2.png) [@Zavan](https://meta.discourse.org/u/Zavan)
#### Post date: [June 20, 2020, 11:55am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/53 "2020-06-20T11:55:44Z")

</div>

That is me squared away. Thank you very much - greatly appreciated.

Can I help out, in return, by writing some of what I have learned into your guide? If not, no dramas; I’m just hoping to pay forward your support.

---

<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: [June 20, 2020, 12:02pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/54 "2020-06-20T12:02:04Z")

</div>

That’s very kind. Would be delighted to have you edit it. You should be able to already? It’s a wiki

You helped me also to refresh my memory 🙂

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 20, 2020, 1:24am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/55 "2020-07-20T01:24:02Z")

</div>

I don’t really need role syncing but a discord bot that posts in specific channels of the discord server when new topics are made in the forum, would be nice. Is there any plugin that can do that?

---

<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 20, 2020, 6:13am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/56 "2020-07-20T06:13:39Z")

</div>

Yeah this plugin is probably not the right tool for that. The bot is powered by your Discourse and can access your Discourse data (where permitted and prompted by command) but runs in a separate thread so will not be signalled by Discourse events.

I guess it might be feasible to extend it at some point to eg watch for a new Topics within a specific category. Not the best use of this architecture but PR welcome.

Sounds like you need to investigate?:

> [@Has any one tried webhooks with Discord?](https://meta.discourse.org/t/has-any-one-tried-webhooks-with-discord/51785/4):
>
> Update: Using Zapier as the middleman, it’s pretty easy to integrate a Discourse webhook to Discord! Use this template for new topics: Result:

Or

> [@Has any one tried webhooks with Discord?](https://meta.discourse.org/t/has-any-one-tried-webhooks-with-discord/51785/7):
>
> Another option is the new discourse-chat-integration plugin I’m working on - it can post new topics to Discord without Zapier or scripts on any other server.

---

<div class="post-metadata">

### Author: ![AntiMetaman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/antimetaman/32/186978_2.png) [@AntiMetaman](https://meta.discourse.org/u/AntiMetaman)
#### Post date: [July 20, 2020, 8:56am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/57 "2020-07-20T08:56:40Z")

</div>

Yep, I investigated both of those options. The first option, Zapier, isn’t free. You can make up to 5 free Zaps and those are single-step zaps. This is exactly what was said in that thread, so the alternative that was proposed was the discourse-chat-integration which is supposedly an official plugin. I think this is the closest way to do what I want to do.

The last option seems to be an RSS feed plugin:

> [@Display a Discourse RSS feed in Discord](https://meta.discourse.org/t/how-to-use-discord-to-display-discourse-rss-feed/47984):
>
> This is a guide that explains how to display RSS feeds from your Discourse forum to your Discord server. You need a Discord Bot. You can use a hosted bot with an RSS cog and add it to your server or install a self-hosted bot and configure it. For this guide, we’ll use [Red-DiscordBot](https://github.com/Cog-Creators/Red-DiscordBot) because it is self-hosted. You can install it on your server. It’s very easy to maintain, highly customizable, and actively maintained. Setting up the bot Follow [this tutorial](https://docs.discord.red/en/stable/) to install and configure Red. C…

Update: After learning to properly setup the rules and configuring the webhooks, the chat-integration does exactly what I wanted! Thanks.

---

<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 5, 2020, 7:14pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/58 "2020-11-05T19:14:09Z")

</div>

Hey @merefield,

thanks again for reaching out with this plugin!

I installed everything like described in the docs. I use this command: `!discsync` and everything is looking good to me. 🥰

However for some users (not for all) I get for all of their groups this error:

```log
Discourse Sync: [11/31] Adding member 'MaxMustermann' to 'Member'
Discourse Sync: I dont appear to have rights to do this though!
ERROR on server XYZ (ID: 123123123123) for command ^add_role, undefined method add_role' for nil:NilClass

```

Other users are able to be sync for the same group 🤔

---

<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 5, 2020, 7:34pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/59 "2020-11-05T19:34:04Z")

</div>

That suggests your `provider_uid` in Discourse is not set for that user. Please investigate.

> <https://github.com/merefield/discourse-discord-bot/blob/b3b3d7f2315b9ecf6a35b27cb0b089cf0766aa54/plugin.rb#L132>

Well done for setting this up btw. It’s quite complex and not for the faint hearted! :).

---

<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 5, 2020, 7:46pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/60 "2020-11-05T19:46:13Z")

</div>

> [@merefield](#):
>
> That suggests your `provider_uid` in Discourse is not set for that user. Please investigate.

I ran this query in the Knowledge Explorer Plugin:

```sql
SELECT *
FROM user_associated_accounts u 
WHERE u.provider_name = 'discord' 

```

I can’t post the result for reasons 😄 but I checked every user for their `provider_uid` and each user has one. Is there anything else I could debug?

---

<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 5, 2020, 10:51pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/61 "2020-11-05T22:51:06Z")

</div>

Then the next most likely issue is that the currently mapped Discord UID is wrong.

ie the data in Discourse is not mapping to a valid UID in Discord.

Check this users record in Discord manually and confirm it is correct.

---

<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 5, 2020, 11:07pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/62 "2020-11-05T23:07:06Z")

</div>

Hey, I can confirm this. The user has another UID in Discourse than in Discord.

How can this issue be reproduced?

---

<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 5, 2020, 11:08pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/63 "2020-11-05T23:08:39Z")

</div>

Could you delete the association and ask the user to recreate by associating Discord once more? If it happens again, something is buggy with the social login?

---

<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 12, 2020, 8:52pm UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/64 "2020-11-12T20:52:58Z")

</div>

Hey,

I just wanted to do an follow up. I was talking to the people who had these issues. We could determine the possible issue.

The User signed up with his old discord account which he didn’t joined the server with. So the Sync Bot could not find the discord user I guess and errored.

---

<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:13am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/65 "2020-11-13T08:13:29Z")

</div>

Thanks for clarifying. Can you confirm how you resolved? Did you delete his association and then get him to reassociate?

---

<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 13, 2020, 8:25am UTC](https://meta.discourse.org/t/discord-bot-construction-kit/122530/66 "2020-11-13T08:25:16Z")

</div>

> [@merefield](#):
>
> Did you delete his association and then get him to reassociate?

That’s what we did. 😊

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

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