1 |
const { default: axios } = require("axios"); |
import { CommandInteraction, Message, MessageEmbed } from 'discord.js'; |
2 |
const { MessageEmbed } = require("discord.js"); |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
|
import DiscordClient from '../../client/Client'; |
4 |
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
import axios from 'axios'; |
7 |
|
import path from 'path'; |
8 |
|
import { deleteFile, download } from '../../utils/util'; |
9 |
|
|
10 |
|
export default class JokeCommand extends BaseCommand { |
11 |
|
supportsInteractions: boolean = true; |
12 |
|
|
13 |
|
constructor() { |
14 |
|
super('joke', 'fun', []); |
15 |
|
} |
16 |
|
|
17 |
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
18 |
|
if (msg instanceof CommandInteraction) |
19 |
|
await msg.deferReply(); |
20 |
|
|
|
module.exports = { |
|
|
async handle(msg, cm) { |
|
21 |
axios.get("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist", { |
axios.get("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist", { |
22 |
headers: { |
headers: { |
23 |
'Accept': 'application/json' |
'Accept': 'application/json' |
25 |
}) |
}) |
26 |
.then(async res => { |
.then(async res => { |
27 |
if (res.data && !res.data.error) { |
if (res.data && !res.data.error) { |
28 |
await msg.reply({ |
await this.deferReply(msg, { |
29 |
embeds: [ |
embeds: [ |
30 |
new MessageEmbed() |
new MessageEmbed() |
31 |
.setColor('#007bff') |
.setColor('#007bff') |
39 |
}); |
}); |
40 |
} |
} |
41 |
else { |
else { |
42 |
await msg.reply({ |
await this.deferReply(msg, { |
43 |
content: "Something went wrong with the API response. Please try again later." |
content: "Something went wrong with the API response. Please try again later." |
44 |
}); |
}); |
45 |
} |
} |
46 |
}) |
}) |
47 |
.catch(async e => { |
.catch(async e => { |
48 |
console.log(e); |
console.log(e); |
49 |
await msg.reply({ |
await this.deferReply(msg, { |
50 |
content: "Something went wrong with the API. Please try again later." |
content: "Something went wrong with the API. Please try again later." |
51 |
}); |
}); |
52 |
}) |
}) |
53 |
} |
} |
|
}; |
|
54 |
|
} |