Report this

What is the reason for this report?

[NSFW] I make discord bots. I am having issues with my NSFW commands working.

Posted on August 6, 2018

the code:

class Util {
  static async scrapeSubreddit(subreddit) {
    subreddit = typeof subreddit === 'string' && subreddit.length !== 0 ? subreddit : "puppies";
    return snekfetch.get(`https:\/\/imgur\/r\/${subreddit}\/hot.json`)
      .then(res => {
        if(!res.body.data) return;
        const img = res.body.data[Math.floor(Math.random() * res.body.data.lenght)];
        return `http://imgur.com/${img.hash}${img.ext.replace(/?.*/, '')}`;
      });
  }
}
module.exports = Util;

That Is for scraping subreddits.

const { Command } = require('klasa');
const subReddits = ["nsfw subreddits"];
const { MessageEmbed } = require("discord.js");
const { scrapeSubreddit }  = require('../../lib/util/functions.js');
module.exports = class extends Command {
  constructor(...args) {
    super(...args, {
      runIn: ['text'],
      cooldown: 3,
      aliases: ['pussies', 'gkitty'],
      description: '"',
      requiredPermissions: ['ATTACH_FILES', 'EMBED_LINKS']
    });
  }
  async run(message) {
    if (!message.channel.nsfw) return message.sendMessage('NOPE! Tried to use a NSFW command inside a SFW channel.');
    try {
      let img = await scrapeSubreddit(subReddits[Math.floor(Math.random() * subReddits.length)]);
      if (!img) return message.sendMessage('Please try again.');
      if (img.indexOf('.mp4')) {
        img = await scrapeSubreddit(subReddits[Math.floor(Math.random() * subReddits)]);
      }
      const embed = new MessageEmbed();
      embed.setColor('PINK');
      embed.setTimstamp();
      embed.setImage(img);
      return message.sendMessage({ embed });
    } catch (e) {
      message.sendMessage('There was an error. It has notified the developer.');
      console.log(e);
      return;
    }
  }
}```

the error:

{ Error: getaddrinfo EAI_AGAIN imgur:443 at Object._errnoException (util.js:1022:11) at errnoException (dns.js:55:15) at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26) code: ‘EAI_AGAIN’, errno: ‘EAI_AGAIN’, syscall: ‘getaddrinfo’, hostname: ‘imgur’, host: ‘imgur’, port: 443 }

Im not sure what is causing this issue, and I tried googling, and it didn't help very much.


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

The EAI_AGAIN code, means the DNS lookup is failing. Form the error output that you’ve shared, you are making the request to imgur:443, and imgur is not a valid hostname. You need to make sure that you’ve specified the correct hostname, eg imgur.com rather than only imgur so that the request could complete successfully.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.