Files
xiao/commands/search/urban.js
T
Daniel Odendahl Jr 12594758be Lots of Stuff
2017-09-18 02:29:10 +00:00

45 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { shorten } = require('../../structures/Util');
module.exports = class UrbanCommand extends Command {
constructor(client) {
super(client, {
name: 'urban',
group: 'search',
memberName: 'urban',
description: 'Searches Urban Dictionary for your query.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'query',
prompt: 'What would you like to define?',
type: 'string'
}
]
});
}
async run(msg, { query }) {
try {
const { body } = await snekfetch
.get('http://api.urbandictionary.com/v0/define')
.query({ term: query });
if (!body.list.length) return msg.say('Could not find any results.');
const data = body.list[0];
const embed = new MessageEmbed()
.setColor(0x32A8F0)
.setAuthor('Urban Dictionary', 'https://i.imgur.com/fzFuuL7.png')
.setURL(data.permalink)
.setTitle(data.word)
.setDescription(shorten(data.definition))
.addField(' Example',
shorten(data.example, 1000) || 'None');
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};