import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; import request from 'node-superfetch'; import * as cheerio from 'cheerio'; export default class FMLFun extends Command { public constructor() { super('fml', { aliases: ['fml'], category: 'fun', description: { content: 'Gives you a random FML.', usage: '', examples: [ '' ] }, ratelimit: 3 }); } public async exec(msg: Message): Promise { //@ts-ignore const { text } = await request.get('http://www.fmylife.com/random').catch(err => { console.error(err); return msg.reply('Woops, there was an error with the (http://www.fmylife.com/random) API.'); }); const $ = cheerio.load(text, { normalizeWhitespace: true }); const fml = $('a.article-link').first().text().trim(); //@ts-ignore return msg.reply(fml); } }