1 |
import { CommandInteraction, Message, MessageEmbed } from 'discord.js'; |
2 |
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 |
|
21 |
axios.get("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist", { |
22 |
headers: { |
23 |
'Accept': 'application/json' |
24 |
} |
25 |
}) |
26 |
.then(async res => { |
27 |
if (res.data && !res.data.error) { |
28 |
await this.deferReply(msg, { |
29 |
embeds: [ |
30 |
new MessageEmbed() |
31 |
.setColor('#007bff') |
32 |
.setTitle('Joke') |
33 |
.setDescription(res.data.type === 'twopart' ? res.data.setup + '\n\n' + res.data.delivery : res.data.joke) |
34 |
.addField('Category', res.data.category) |
35 |
.setFooter({ |
36 |
text: `ID: ${res.data.id}` |
37 |
}) |
38 |
] |
39 |
}); |
40 |
} |
41 |
else { |
42 |
await this.deferReply(msg, { |
43 |
content: "Something went wrong with the API response. Please try again later." |
44 |
}); |
45 |
} |
46 |
}) |
47 |
.catch(async e => { |
48 |
console.log(e); |
49 |
await this.deferReply(msg, { |
50 |
content: "Something went wrong with the API. Please try again later." |
51 |
}); |
52 |
}) |
53 |
} |
54 |
} |