/[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 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2051 byte(s)
Release version 2.0
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     import path from 'path';
8     import { deleteFile, download } from '../../utils/util';
9 rakin 49
10 rakin 51 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 rakin 49 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 rakin 51 await this.deferReply(msg, {
29 rakin 49 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 rakin 51 await this.deferReply(msg, {
43 rakin 49 content: "Something went wrong with the API response. Please try again later."
44     });
45     }
46     })
47     .catch(async e => {
48     console.log(e);
49 rakin 51 await this.deferReply(msg, {
50 rakin 49 content: "Something went wrong with the API. Please try again later."
51     });
52     })
53     }
54 rakin 51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26