I'm trying to make a meme bot (that uses reddit), but some of the subreddits have an NSFW warning page, which stops random-puppy from getting the images, how do i bypass that? I am welcome to getting alternates for random-puppy if you know about something better
module.exports = {
name: "meme",
description: "Sends a meme",
async execute(message, args){
const Discord = require("discord.js");
const bot = new Discord.Client();
const ms = require("ms");
const moment = require("moment");
const colors = require("colors");
const randomPuppy = require("random-puppy");
const memeSubreddits = ["dankmemes", "memes", "meme", "me_irl", "meirl", "comedyheaven", "NSFWMemes", "okbuddyretard"]
const memeRandom = memeSubreddits[Math.floor(Math.random() * memeSubreddits.length)];
const memeImage = await randomPuppy(memeRandom);
const memeEmbed = new Discord.RichEmbed()
.setColor("RANDOM")
.setImage(memeImage)
.setTitle(`From r/${memeRandom}`)
.setURL(`https://reddit.com/r/${memeRandom}`);
message.channel.send(memeEmbed);
}
}
I'd recommend using memejs for getting memes from Reddit. As its package name suggests, it gets memes but you can also filter what it gathers from.
As an example, you can do this:
module.exports = {
name: "meme",
description: "Sends a meme",
guildOnly: true,
execute(message) {
const {
meme
} = require('memejs');
meme(function (err, data) {
if (err) return console.error(err);
const Discord = require('discord.js');
const memeRes = new Discord.RichEmbed()
.setTitle(data.title)
.setImage(data.url)
.setFooter(data.subreddit)
.setTimestamp('Created ' + data.created)
message.channel.send(memeRes).then().catch(console.error);
});
},
}
As with every Node package you can play around with them on RunKit. You can do that here
Also, as a little tip, you do not need to declare modules that are not being used in the command. This essentially gets rid of the following from your command:
const bot = new Discord.Client();
const ms = require("ms");
const moment = require("moment");
const colors = require("colors");