Files
xiao/commands/random/word-of-the-day.js
T
Daniel Odendahl Jr c443e68f7f ALIASES
2017-09-25 16:58:05 +00:00

33 lines
969 B
JavaScript

const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { WORDNIK_KEY } = process.env;
module.exports = class DefineCommand extends Command {
constructor(client) {
super(client, {
name: 'word-of-the-day',
aliases: ['wordnik-word-of-the-day'],
group: 'random',
memberName: 'word-of-the-day',
description: 'Gets the word of the day.',
clientPermissions: ['EMBED_LINKS']
});
}
async run(msg) {
try {
const { body } = await snekfetch
.get('http://api.wordnik.com/v4/words.json/wordOfTheDay')
.query({ api_key: WORDNIK_KEY });
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setTitle(body.word)
.setDescription(`(${body.definitions[0].partOfSpeech}) ${body.definitions[0].text}`);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};