diff options
Diffstat (limited to 'src/commands/jokes.js')
-rw-r--r-- | src/commands/jokes.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/commands/jokes.js b/src/commands/jokes.js new file mode 100644 index 0000000..578e51b --- /dev/null +++ b/src/commands/jokes.js @@ -0,0 +1,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); + } +}
\ No newline at end of file |