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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.