UNPKG

sectom

Version:

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

34 lines (28 loc) 957 B
const { default: axios } = require("axios"); const discord = require("discord.js"); const { stringToBoolean } = require("./stringToBoolean"); async function urban(name, asJSON = false) { try { const query = encodeURIComponent(name); const { data: { list }, } = await axios.get( `https://api.urbandictionary.com/v0/define?term=${query}` ); const [answer] = list; const embed = new discord.MessageEmbed() .setTitle(answer.word) .setURL(answer.permalink) .addField( `Definition`, trim(answer.definition).replace("[", "").replace("]", "") ) .addField(`Example`, trim(answer.example)) .setFooter(`👍 ${answer.thumbs_up} 👎 ${answer.thumbs_down}`); if (typeof asJSOn == "undefined") return embed; if (stringToBoolean(asJSON)) return embed.toJSON(); } catch (error) { console.log(error); } } module.exports = urban;