nyx/command/Fun/cat.js

36 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-09-06 12:38:25 +02:00
const { MessageEmbed } = require("discord.js");
const fetch = require("node-fetch");
module.exports = {
name: "cat",
category: "Fun",
description: "Get a cat from reddit",
run: async (client, interaction, args) => {
let subreddits = ["cat", "cats"];
let subreddit = subreddits[Math.floor(Math.random() * subreddits.length)];
fetch(`https://www.reddit.com/r/${subreddit}/random/.json`).then(
async res => {
let content = await res.json();
let permalink = content[0].data.children[0].data.permalink;
let memeURL = `https://reddit.com${permalink}`;
let memeImage = content[0].data.children[0].data.url;
let memeTitle = content[0].data.children[0].data.title;
let memeUpvotes = content[0].data.children[0].data.ups;
let memeDownvotes = content[0].data.children[0].data.downs;
let memeNumComments = content[0].data.children[0].data.num_comments;
const memeEmbed = new MessageEmbed()
.setTitle(`A cat image | ${memeTitle}`)
.setAuthor(
interaction.member.user.tag,
interaction.user.displayAvatarURL({ dynamic: true })
)
.setURL(`${memeURL}`)
.setImage(memeImage)
.setTimestamp()
.setColor(client.color)
.setFooter(` 👍 ${memeUpvotes} 💬 ${memeNumComments}`);
await interaction.followUp({ embeds: [memeEmbed] });
}
);
},
};