/[sudobot]/trunk/src/commands/fun/JokeCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/fun/JokeCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26