aboutsummaryrefslogtreecommitdiff
path: root/src/commands/jokes.js
blob: 578e51b2f9645dd3723e51643e15627f9fbdce03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fetch = require('node-fetch');

function randomJokes(message) {
    message.channel.startTyping();
    getJokes().then(response => {
        message.channel.stopTyping();
        if (response) {
            message.channel.startTyping();
            message.reply(response.setup);
            setTimeout(() => {
                message.channel.stopTyping();
                message.reply(`||${response.punchline}||`);
            }, 5000);
        }
    });
}

async function getJokes() {
    return fetch(`https://official-joke-api.appspot.com/jokes/random`)
        .then(res => res.json())
}


module.exports = {
    execute(client,message, args) {
        randomJokes(message);
    }
}