/[sudobot]/branches/2.x/src/commands/fun/JokeCommand.ts
ViewVC logotype

Annotation of /branches/2.x/src/commands/fun/JokeCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 2072 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 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     coolDown = 4000;
13    
14     constructor() {
15     super('joke', 'fun', []);
16     }
17    
18     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
19     if (msg instanceof CommandInteraction)
20     await msg.deferReply();
21    
22     axios.get("https://v2.jokeapi.dev/joke/Any?blacklistFlags=nsfw,religious,political,racist", {
23     headers: {
24     'Accept': 'application/json'
25     }
26     })
27     .then(async res => {
28     if (res.data && !res.data.error) {
29     await this.deferReply(msg, {
30     embeds: [
31     new MessageEmbed()
32     .setColor('#007bff')
33     .setTitle('Joke')
34     .setDescription(res.data.type === 'twopart' ? res.data.setup + '\n\n' + res.data.delivery : res.data.joke)
35     .addField('Category', res.data.category)
36     .setFooter({
37     text: `ID: ${res.data.id}`
38     })
39     ]
40     });
41     }
42     else {
43     await this.deferReply(msg, {
44     content: "Something went wrong with the API response. Please try again later."
45     });
46     }
47     })
48     .catch(async e => {
49     console.log(e);
50     await this.deferReply(msg, {
51     content: "Something went wrong with the API. Please try again later."
52     });
53     })
54     }
55     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26