UNPKG

sectom

Version:

Sectom is a useful npm package that has multiple easy to use functions.

38 lines (33 loc) 1.25 kB
const { stringToBoolean } = require("./stringToBoolean"); const { MessageEmbed } = require("discord.js"); const got = require("got"); /** * * @param {boolean} asJSON - A boolean telling the function if it should return a JSON embed or an embed */ function generateDiscordMemeEmbed(asJSON = false) { const embed = new MessageEmbed(); got("https://www.reddit.com/r/memes/random/.json") .then((response) => { const [list] = JSON.parse(response.body); const [post] = list.data.children; const permalink = post.data.permalink; const memeUrl = `https://reddit.com${permalink}`; const memeImage = post.data.url; const memeTitle = post.data.title; const memeUpvotes = post.data.ups; const memeNumComments = post.data.num_comments; embed.setTitle(`${memeTitle}`); embed.setURL(`${memeUrl}`); embed.setColor("RANDOM"); embed.setImage(memeImage); embed.setFooter(`👍 ${memeUpvotes} 💬 ${memeNumComments}`); if (typeof asJSON !== "undefined" && stringToBoolean(asJSON)) { return embed.toJSON(); } else { return embed; } }) .catch(console.error); } module.exports = generateDiscordMemeEmbed;