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

August 6, 2018 158 views
Applications Ubuntu 16.04

the code:
``const snekfetch = require('snekfetch');
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: ['ATTACHFILES', 'EMBEDLINKS']
});
}
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.

Be the first one to answer this question.