<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Spyder</title>
    <description>The latest articles on DEV Community by Spyder (@spyderexe).</description>
    <link>https://dev.to/spyderexe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F87888%2Fcabd24b2-969a-4b36-bc87-a2e4e2c18238.png</url>
      <title>DEV Community: Spyder</title>
      <link>https://dev.to/spyderexe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/spyderexe"/>
    <language>en</language>
    <item>
      <title>Need help with Discord Webhooks</title>
      <dc:creator>Spyder</dc:creator>
      <pubDate>Sat, 28 Jul 2018 15:05:22 +0000</pubDate>
      <link>https://dev.to/spyderexe/need-help-with-discord-webhooks-6b7</link>
      <guid>https://dev.to/spyderexe/need-help-with-discord-webhooks-6b7</guid>
      <description>

&lt;p&gt;&lt;b&gt; Hello DEV.to community! First off I'd like to apologize if this is not the correct place to post this, it seems at first glance that this is a place to write and post articles and less to post coding errors, but in the doubt I really would like answers as other forums (Stack) didn't help much &lt;/b&gt;&lt;/p&gt;

&lt;p&gt;I'm not really experienced in Node.js and javascript and all that and I wanted to add a webhook to my discord server. I found this github project that I'd like to implement: &lt;a href="https://github.com/FrankenMan/me_irl-webhook"&gt;https://github.com/FrankenMan/me_irl-webhook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I followed the discord documentation, made a fork, added the webhook, and everything seems to work (I get automatic discord messages everytime I make a commit), however the bot doesn't do anything.&lt;/p&gt;

&lt;p&gt;here's my fork: &lt;a href="https://github.com/Spyder-exe/me_irl-webhook/"&gt;https://github.com/Spyder-exe/me_irl-webhook/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I did a bit of research, and I found that the bot needed a config.json file and a posts.json file. So I renammed the config.json.example and added my webhook's id and token, I created a blank posts.json file.&lt;/p&gt;

&lt;p&gt;I also changed the package.json file as the project was a year old from that:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "discord.js": "^11.0.0",
  "erlpack": "github:hammerandchisel/erlpack",
  "request": "^2.79.0",
  "uws": "^0.13.0"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "discord.js": "&amp;gt;=11.0.0",
  "erlpack": "github:discordapp/erlpack",
  "request": "&amp;gt;=2.79.0",
  "uws": "&amp;gt;=0.13.0"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;However the bot still doesn't seem to do anything, here's the main bot.js code, again I'm not that experienced with Javascript so I can't tell what's wrong&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Discord = require('discord.js');
const request = require('request');
const fs = require('fs');
const config = require('./config.json');
const posts = require('./posts.json');


const webhook = new Discord.WebhookClient(config.webhookid, config.webhooktoken);

const postDict = JSON.parse(fs.readFileSync('./posts.json', 'utf8'));
//function for logging ids and urls of posts to stop repeat posts.
function postLog(postId, postUrl) {
    postDict[postId] = {
    url: postUrl
  }
  fs.writeFile('./posts.json',JSON.stringify(postDict), (err) =&amp;gt; {
    if (err) console.error(err)
  })
}


function fetchRedditPost() {
request(config.url, function(error,response,body) {
      var ok = JSON.parse(body)
      ok.data.children.forEach(function(ok){
        let NUT = "imgur.com"
        let ext = ".jpg"
        let otherExt = ".gif"
        let dril = ".gifv"
        let r34 = ".png"
        let alb = "/a/"
        //checking if it's an imgur link without .jpg, .gif, .gifv, .png
    if (ok.data.url.includes(NUT) &amp;amp;&amp;amp; !ok.data.url.includes(ext &amp;amp;&amp;amp; otherExt &amp;amp;&amp;amp; dril &amp;amp;&amp;amp; r34)) {
       const SHACK = ok.data.url + ext
       //skip imgur album links
     if (ok.data.url.includes(alb)) return;
     //check if this post has been logged. If false, post it on Discord and log it, if true, do not post it
      if (!postDict[ok.data.id]){
        webhook.sendMessage(`${ok.data.title}\n${SHACK}`);
       postLog(ok.data.id, SHACK)
      }
      else {
         return
      }
    }
    //urls containing i.reddituploads.com don't show up in Discord
    else if (ok.data.url.includes("i.reddituploads.com")){
     if (!postDict[ok.data.id]) {
     postLog(ok.data.id,ok.data.preview.images[0].source.url);
     webhook.sendMessage(`${ok.data.title}\n${ok.data.preview.images[0].source.url}`)
     }
     else {
        return;
     }
    }
    else{
      if (!postDict[ok.data.id]){
        postLog(ok.data.id, ok.data.url)
        webhook.sendMessage(`${ok.data.title}\n${ok.data.url}`);
      }
      else{
        return;
      }

    };
      })
})
};
function redditInterval() {
 setInterval(() =&amp;gt; (fetchRedditPost()), 36000);
}
redditInterval();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>help</category>
      <category>node</category>
    </item>
  </channel>
</rss>
