Search any word through discord
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios')
if(context.params.event.content.startsWith("!urban")) {
const args = context.params.event.content.split(" ").slice(1)
if(!args[0]) return await lib.discord.channels['@0.1.1'].messages.create({
channel_id: context.params.event.channel_id,
content: `Please provide something to search!`,
});
const { data } = await axios(`https://api.urbandictionary.com/v0/define?page=1&term=${encodeURIComponent(args.join(" "))}`)
if(!data.list.length) return await lib.discord.channels['@0.1.1'].messages.create({
channel_id: context.params.event.channel_id,
content: `Unable to find any word with this name`,
});
const target = data.list[Math.floor(Math.random()*data.list.length)];
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: context.params.event.channel_id,
content: ``,
embed: {
title: target.word,
url: target.permalink,
color: 0xffa500,
description: target.definition.replace(/\[|\]/g, "**"),
fields: [
{ name: "Example", value: target.example.replace(/\[|\]/g, "`" )}
],
footer: { text: `👍 ${target.thumbs_up} | 👎 ${target.thumbs_down}` }
}
});
}