MyBB Community Forums

Full Version: [DEV] Send information about new posts and threads to Discord channel using WebHooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6
Would be nice to add it into MyBB extend section... I am looking forward to see support for thread colors (check Github). Thank you!
Hi!

@fishu It should be possible to find forum usernames prepended by @ character and replace them to corresponded additional field which contains user's discord ID. I'll add this idea to the list on github.

@eldenroot I'll work on that soon Smile should be ready in first days of May
This is amazing. Good work!

I was wondering, would it be possible in the future to push threads based on Prefix? For example, if someone posts a thread using Prefix A, in any approved board, it will post to the Discord. But if the thread doesn't have Prefix A, it won't post to the Discord?

'cause that would be insanely useful!

Thanks for sharing this!
Hi! I am having an odd issue What i am seeing is that while its MOSTLY reliable (the plug in) every once in a while the messages don't send. I can't consistantly replicate a condition for it NOT to send, and it seems some of my users are more effected then others, all using Chrome (including me). Is there anything I can look for that might be stopping the send?


@ryczypior
Hi! Yep I have a hard code that does exactly that. It would be super if it was part of the GUI (which if i knew how/where that was coded i'd do my self lol) my hard code scrubs the post  for an array of @usernames and appeneds the correct @discorduserid's to the end of message. 

 protected function RemoveTags($msg) {
            $from = array(
                '@UserA',
                '@UserB',
         
            );
                  
                return str_ireplace($from, '', $msg);
        }


         protected function ReplaceTagging($msg) {
            $from = array(
                '@Usera',
                '@Userb',
           
            );
            $to = array(
                '<@211111111111111112>', //UserA
                '<@200000000000000000>', //Userb
);
             
       
        protected function send($username, $message, $msg, $avatar = null, $embeds = null, $tts = false) {
        $msg= $this->ReplaceTagging($msg);
            $push = json_encode(array(
                'username' => $username,
                'avatar_url' => $avatar,
                'content' => ($message.$msg),
                'embeds' => $embeds,
                'tts' => $tts,
                    ), JSON_NUMERIC_CHECK);
            if ($mybb->settings['discord_webhooks' . $suffix . '_usesocket']) {
                $this->sendSocket($push, $this->endpointURL);
            } else {
                $this->sendCURL($push, $this->endpointURL);
            }
            return $this;
        } 


Then in the reply/new post i put this in 

        $msgb=$discordWebhook->RemoveTags($msg);
                            if (mb_strlen($msgb, 'UTF-8') > $limit) {
                                $msgb = mb_strcut($msgb, 0, $limit, 'UTF-8') . '...';
                            }
        $color = $discordWebhook->getColorIntFromHex($color);
                            $embeds = array(
                                array(
                                    'type' => "rich",
                                    'title' => $title,
                                    'description' => $msgb,
                                    'url' => $url,
                                    'color' => $color,
                                    'author' => $author,
                                    'thumbnail' => $thumbnail,
                                ),
                            );
                        }
                       $discordWebhook->send($botname, $message,$msg, null, $embeds);
So the tags wouldn't be part of the posted message to discord if they were in the first part of the post (and tag twice)
After the update;

"Install & Activate" results in;
This page isn’t working
[WEBSITE] is currently unable to handle this request.
HTTP ERROR 500

I am unsure how to fix this?

Thank you!


EDIT TO ADD:
... Ummm....

[Image: 1741d754ac3101a8be799930c71d94d7.png]

Why are they all here? I removed the files for the additional from the FTP?
@ThistleProse I've pushed fixes for multiinstance, I've forgot about it last night Smile
About these multiple settings - it's because install failure, you can get rid of them by removing discord_webhooks{suffix} sections from {prefix}_settinggroups table and options from {prefix}_settings
Thank you!

I have found that tagging a group in the "New Thread/Post Message" is no longer working. It posts the @Role in the correct colour etc, but it isn't causing a tag to happen.

This is my New Post Message content;
<@&340629102455291904>

A new tag has been posted by **{username}**!

**Title:** {threadtitle}
**Location:** {boardname}
**Link:** {url}

Which creates this:
[Image: 152779e34e967faa2d64385ea3d6f5d0.png]

but used to create this:
[Image: cb005d97329980bfa317064b1a3b724a.png]

Any idea what I'm doing wrong? Or is it something with the code?

Never mind!

Changed it from "Rich text (info message will be pretended to text)" to "Info message with rich text" and it tags now Big Grin

EDIT AGAIN:

"Only Info message as rich text" isn't tagging Sad I need it to tag without having to show any content. (temp getting around this by having it only show 1 character)
I'll check if it's even possible to mention users in rich message. As you can see tagging works OK (@<@&340629102455291904> changes to @Player). Maybe "Only info message" option will be suitable for you?
Yeah; it changes like it should. But in the second image (previous release) it actively tagged.
In the second image, it changes to the @Role, but it isn't causing the message to 'tag'. It just... exists XD

And yeah, maybe, but I want the goodies like the Avatar Toungue
Hmm Smile In previous version It was "Only info message" option which worked like in current rel. Maybe if setting 0 characters length for rich msg will cause no message at all it will be ok for you?
Pages: 1 2 3 4 5 6