require('dotenv').config(); const Discord = require('discord.js'); const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] }); const axios = require('axios'); const slashcommands = require('./config/slash.json'); const authors = require('./config/authors.json'); client.on("ready", () => { console.log(`Running at ${client.user.tag}!`); }); client.on("messageCreate", async message => { if (message.author.bot) return; if (message.channel.type === "DM") return; if (authors.includes(message.author.id) && message.content.toLowerCase() === "j.deploy") { console.log("Updating slash commands..."); client.application.commands.set(slashcommands); } if (message.content.toLowerCase().includes("-ass ")) { const rearrangedMessage = message.content.toLowerCase().replace(/\-ass\ /g, " ass-"); message.delete(); message.channel.createWebhook(message.author.username, { avatar: message.author.displayAvatarURL() }) .then(async webhook => { await webhook.send({ content: rearrangedMessage }); await webhook.delete(); }) } }); client.on("interactionCreate", async interaction => { if (interaction.isCommand()) { if (interaction.commandName === "joke") { jokeCommand(interaction); } } }); const jokeCommand = async interaction => { interaction.deferReply(); let category; interaction.options.get("category") ? category = interaction.options.get("category").value : category = "Any"; axios.get(`https://v2.jokeapi.dev/joke/${category}?blacklistFlags=nsfw,religious,political,racist,sexist,explicit`) .then(async response => { const data = response.data; const jokeEmbed = new Discord.MessageEmbed().setAuthor(`Category: ${data.category}`); if (data.type === "single") { jokeEmbed.setDescription(data.joke); } else if (data.type === "twopart") { jokeEmbed.setTitle(data.setup); jokeEmbed.setDescription(`||${data.delivery}||`); } await interaction.followUp({ embeds: [jokeEmbed] }); }); } client.login(process.env.TOKEN);