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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26