Advertisement:

Author Topic: Post to Discord  (Read 8985 times)

Offline cedgil

  • Newbie
  • *
  • Posts: 1
Post to Discord
« on: February 05, 2018, 03:08:18 PM »
Not quite sure this is the right place, anyway, ad I ould lihe SMF to interact with Discord, I guess it might be.

A long time ago, I has SMF to post in a Simpleportal shoutbox with this code in post.php :
Code: [Select]
/////////////////////////////////////
// Post new subjects to shoutbox 1 //
/////////////////////////////////////
global $user_info, $board, $scripturl, $boardName, $topic;

$smcFunc['db_insert']('',
'{db_prefix}sp_shouts',
array(
'id_shoutbox' => 'int',
'id_member' => 'int',
'member_name' => 'string',
'log_time' => 'int',
'body' => 'string',
),
array(
1,
$user_info['id'],
$user_info['name'],
time(),
'[color=red][i]a posté nouveau sujet: [url='.$scripturl . '?topic=' . $topic . '.new#new'.']'.html_entity_decode($_POST['subject']).'[/url][/i][/color]',
),
array('id_shout')
);
////////////////////////////////////////////
// End of post new subjects to shoutbox 1 //
////////////////////////////////////////////

As I want to my forum to interact closely with Discord, I'd like to do the same thing : whenever there's a new post on the forum, I want it to be announced on Discord. Yet, I didn't manage to have it work, whatever I try.

Here's is the best help I have found is (magazine.gaiscioch.com/guides/posting_to_discord_using_php_and_webhooks.html) :

The first part of this script is a function that will handle posting the data to your discord.
Code: [Select]
<?PHP
function discordmsg($msg, $webhook) {
  if($webhook != "") {
    $ch = curl_init($webhook);
    $msg = "payload_json=" . urlencode(json_encode($msg))."";
   
    if(isset($ch)) {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
      $result = curl_exec($ch);
      curl_close($ch);
      return $result;
    }
  }
}
?>

The next part is the actual action and message you wish to send.
Code: [Select]
<?PHP
// URL FROM DISCORD WEBHOOK SETUP
$webhook = "https://discordapp.com/api/webhooks/xxxxxxxxx/xxxxxxxx";
$msg = json_decode('
{
    "username":"BOTNAME",
    "content":"The message the BOTNAME posts.",
    "embeds": [{
        "title":"The Link Title",
        "description":"The Link Description",
        "url":"https://www.thelinkurl.com/",
        "color":DECIMALCOLORCODE,
        "author":{
            "name":"Site Name",
            "url":"https://www.sitelink.com/",
            "icon_url":"URLTOIMG"
        },
        "fields":[
            {
                "name":"LISTITEM1",
                "value":"LISTVALUE1",
                "inline":true
            },
            {
                "name":"LISTITEM2",
                "value":"LISTVALUE2",
                "inline":true
            },
            {
                "name":"LISTITEM3",
                "value":"LISTVALUE3",
                "inline":true
            }]
    }]
}
', true);
 ?>

Lastly there's the call to fire the script.
Code: [Select]
<?PHP
discordmsg($msg, $webhook); // SENDS MESSAGE TO DISCORD
?>

Could anyone help me with getting it to work? Thanks in advance for any help.

Online Aleksi "Lex" Kilpinen

  • A Peculiar Finn
  • Lead Support Specialist
  • SMF Super Hero
  • *
  • Posts: 17,500
  • Gender: Male
  • Don't worry, I'm n00b friendly
    • Aleksi.Kilpinen on Facebook
    • aleksi-kilpinen on LinkedIn
Re: Post to Discord
« Reply #1 on: February 08, 2018, 12:36:44 PM »
Perhaps try to see how similar stuff has been made for other platforms like Twitter?
For example there's this SimpleTwitter
A Finnish Support Specialist
 Happily running multiple SMF 2.0 installations.

How you can help SMF

"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum.
 Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Offline butch2k

  • Full Member
  • ***
  • Posts: 416
  • Gender: Male
    • @butch2k on Twitter
    • Planète Roliste
Re: Post to Discord
« Reply #2 on: February 12, 2018, 02:56:37 AM »
I use the RSS bot to do this.

Online Aleksi "Lex" Kilpinen

  • A Peculiar Finn
  • Lead Support Specialist
  • SMF Super Hero
  • *
  • Posts: 17,500
  • Gender: Male
  • Don't worry, I'm n00b friendly
    • Aleksi.Kilpinen on Facebook
    • aleksi-kilpinen on LinkedIn
Re: Post to Discord
« Reply #3 on: February 14, 2018, 06:08:33 AM »
That's an option too. :)
A Finnish Support Specialist
 Happily running multiple SMF 2.0 installations.

How you can help SMF

"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum.
 Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,576
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Post to Discord
« Reply #4 on: September 09, 2018, 04:44:52 PM »
Also I just posted a new free mod for discord web hooks https://www.smfhacks.com/index.php?action=downloads;sa=view;down=212 also pending approval on the smf mod site.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Offline lup1n2

  • Newbie
  • *
  • Posts: 7
Re: Post to Discord
« Reply #5 on: October 18, 2018, 11:02:03 AM »
Also I just posted a new free mod for discord web hooks hxxp:www.smfhacks.com/index.php?action=downloads;sa=view;down=212 [nonactive] also pending approval on the smf mod site.
downloaded, Installed, Used, Awesome. I have 1 request could it send shoutbox messages to discord? . Because if it did this would be the cherry on top of the cake :)

Offline vbgamer45

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 20,576
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
Re: Post to Discord
« Reply #6 on: October 18, 2018, 11:32:23 AM »
That would have to be custom built since the shoutbox is not part of SMF by default.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro