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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26