UNPKG

nidhishpackage

Version:

This is a fun package for [Discord](https://discord.com) The library is [Discord.js](https://discord.js.org)

57 lines (47 loc) 2.27 kB
const { MessageEmbed, Message } = require("discord.js"); async function animalimage(message, options = {}) { if(!message) throw new Error('message is not defiend') let Animals = ["dog", "cat", "duck", "bird", "panda", "wolf", "fox", "seal", "llama", "alpaca", "camel", "lizard"], res, json, Data; const Fetch = require(`node-fetch`) if (!options.Animal) { Animals = Animals[Math.floor(Math.random() * Animals.length)]; res = await Fetch(`https://apis.duncte123.me/animal/${Animals.toLowerCase()}`, { headers: { "user-agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; PalmSource/hspr-H102; Blazer/4.0) 16;320x320" } }), json = await res.json(); if (!json.data.file) throw new Error(`Something Went Wrong, Try Again Later!`); const embed = new MessageEmbed() .setColor(options.Color || "RANDOM") .setImage(json.data.file) .setTimestamp() if (options.ResultOnly && options.ResultOnly === true) return { Result: json.data.file }; return message.channel.send(embed); } else { if (!Animals.find(Ani => Ani === options.Animal.toLowerCase())) throw new Error(`Invalid Animal Provided - ${Animals.map(Ani => Ani.charAt(0).toUpperCase() + Ani.slice(1)).join(", ")}`); res = await Fetch(`https://apis.duncte123.me/animal/${options.Animal.toLowerCase()}`, { headers: { "user-agent": "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; PalmSource/hspr-H102; Blazer/4.0) 16;320x320" } }), json = await res.json(); if (!json.data.file) throw new Error(`Something Went Wrong, Try Again Later!`); Data = { embed: { color: options.Color || "RANDOM", image: { url: json.data.file }, timestamp: new Date() } }; const embed = new MessageEmbed() .setColor(options.Color || "RANDOM") .setImage(json.data.file) .setTimestamp() if (options.ResultOnly && options.ResultOnly === true) return { Result: json.data.file }; return message.channel.send(embed); }; }; module.exports = animalimage