Victor10782

Comando para enviar fotos aleatorias de Gatos e Cachorros

Feb 8th, 2024 (edited)
1,305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.28 KB | Source Code | 0 0
  1. /*Comando para enviar fotos aleatorias de Gatos e Cachorros, fiz só por fazer
  2. Packages: discord.js ( Versão 14.11.0 )
  3. axios ( Versão 1.6.7 )
  4.  
  5. Créditos da API usada no Código: https://api.alexflipnote.dev/*/
  6.  
  7. const Discord = require("discord.js");
  8. const axios = require("axios");
  9.  
  10. module.exports = {
  11.     name: "foto",
  12.     description: "Enviar fotos aleatorias no chat",
  13.     options: [{
  14.         name: "tipo",
  15.         description: "Escolha o tipo de imagem",
  16.         type: Discord.ApplicationCommandOptionType.String,
  17.         required: true,
  18.         choices: [{
  19.             name: "Gatos",
  20.             value: "cat"
  21.         }, {
  22.             name: "Cachorros",
  23.             value: "dog"
  24.         }]
  25.     }],
  26.     run: async (client, inter) => {
  27.         try {
  28.             await inter.deferReply().catch((_) => {});
  29.             let res;
  30.             let option = inter.options.getString("tipo");
  31.  
  32.             switch (option) {
  33.                 case "cat":
  34.                     await axios.get("https://api.alexflipnote.dev/cats").then(r => {
  35.                         res = r.data;
  36.                     });
  37.                     break;
  38.                 case "dog":
  39.                     await axios.get("https://api.alexflipnote.dev/dogs").then(r => {
  40.                         res = r.data;
  41.                     });
  42.                     break;
  43.             }
  44.             let row = new Discord.ActionRowBuilder().addComponents(new Discord.ButtonBuilder().setLabel("Deletar").setStyle(Discord.ButtonStyle.Danger).setCustomId("botao").setEmoji("🗑️"));
  45.  
  46.             let img = new Discord.AttachmentBuilder(res.file);
  47.             let msg = await inter.editReply({ files: [img], components: [row], fetchReply: true
  48.             });
  49.             let c = msg.createMessageComponentCollector({ time: 600000 })
  50.  
  51.             c.on("collect", async i => {
  52.                 if (inter.user.id !== i.user.id) {
  53.                     return await i.reply({ content: "Você não é o autor deste comando, portanto não pode deletar a mensagem.", ephemeral: true
  54.                     });
  55.                 }
  56.                 let fetchMsg = await i.channel.messages.fetch(i.message.id);
  57.                 await fetchMsg.delete();
  58.             });
  59.         } catch (err) {
  60.             console.error(err)
  61.         }
  62.     }
  63. }
Tags: discord.js
Advertisement
Add Comment
Please, Sign In to add comment