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.
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
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 toimgur:443
, andimgur
is not a valid hostname. You need to make sure that you’ve specified the correct hostname, egimgur.com
rather than onlyimgur
so that the request could complete successfully.Best,
Bobby