Skip to content

Commit

Permalink
[Enhancement] replaced repeated code with the new requestAPI function
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Sep 1, 2021
1 parent a931beb commit 8098f82
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions commands/fun/jokes.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const fetch = require("node-fetch");
const { requestAPI } = require("../../modules/requestAPI");

module.exports = {
data: new SlashCommandBuilder()
.setName("joke")
.setDescription("gets a random joke!"),
async execute(interaction, client) {
await interaction.deferReply();
async function getJoke() {
try {
const requestInsult = await fetch(
"https://v2.jokeapi.dev/joke/Miscellaneous,Dark,Pun,Spooky,Christmas"
);
const responseToJson = await requestInsult.json();
return responseToJson;
} catch (err) {
throw err;
}
}

try {
const joke = await getJoke();
const joke = await requestAPI(
"https://v2.jokeapi.dev/joke/Miscellaneous,Dark,Pun,Spooky,Christmas"
);

const embed = {
color: "#9dcc37",
Expand Down

0 comments on commit 8098f82

Please sign in to comment.