Files
xiao/commands/random-res/advice.js
T
2020-03-23 11:42:43 -04:00

33 lines
833 B
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
module.exports = class AdviceCommand extends Command {
constructor(client) {
super(client, {
name: 'advice',
aliases: ['advice-slip'],
group: 'random-res',
memberName: 'advice',
description: 'Responds with a random bit of advice.',
credit: [
{
name: 'Advice Slip',
url: 'https://adviceslip.com/',
reason: 'API',
reasonURL: 'https://api.adviceslip.com/'
}
]
});
}
async run(msg) {
try {
const { text } = await request.get('http://api.adviceslip.com/advice');
const body = JSON.parse(text);
return msg.say(`${body.slip.advice} (#${body.slip.slip_id})`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};