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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/commands/joke.js revision 49 by rakin, Mon Jul 29 17:28:21 2024 UTC trunk/src/commands/fun/JokeCommand.ts revision 56 by rakin, Mon Jul 29 17:28:24 2024 UTC
# Line 1  Line 1 
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        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    
 module.exports = {  
     async handle(msg, cm) {  
22          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", {
23              headers: {              headers: {
24                  'Accept': 'application/json'                  'Accept': 'application/json'
# Line 10  module.exports = { Line 26  module.exports = {
26          })          })
27          .then(async res => {          .then(async res => {
28              if (res.data && !res.data.error) {              if (res.data && !res.data.error) {
29                  await msg.reply({                  await this.deferReply(msg, {
30                      embeds: [                      embeds: [
31                          new MessageEmbed()                          new MessageEmbed()
32                          .setColor('#007bff')                          .setColor('#007bff')
# Line 24  module.exports = { Line 40  module.exports = {
40                  });                  });
41              }              }
42              else {              else {
43                  await msg.reply({                  await this.deferReply(msg, {
44                      content: "Something went wrong with the API response. Please try again later."                      content: "Something went wrong with the API response. Please try again later."
45                  });                  });
46              }              }
47          })          })
48          .catch(async e => {          .catch(async e => {
49              console.log(e);              console.log(e);
50              await msg.reply({              await this.deferReply(msg, {
51                  content: "Something went wrong with the API. Please try again later."                  content: "Something went wrong with the API. Please try again later."
52              });              });
53          })          })
54      }      }
 };  
55    }

Legend:
Removed from v.49  
changed lines
  Added in v.56

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26