const { Client, Intents, MessageEmbed } = require("discord.js"); const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, ], partials: ["MESSAGE", "REACTION", "USER"], }); const Paginator = require("../../paginator"); module.exports = { name: 'snipe', description: 'snipe', type: 'CHAT_INPUT', options: [ { name: 'channel', description: 'select a channel -optional', type: 3, required: false } ], /** * @param {Client} client * @param {CommandInteraction} interaction */ run: async(client, interaction) => { try { const snipes = {}; const channel = interaction.options.getChannel("channel") || interaction.channel; const formatEmoji = (emoji) => { return !emoji.id || emoji.available ? emoji.toString() // bot has access or unicode emoji : `[:${emoji.name}:](${emoji.url})`; // bot cannot use the emoji }; process.on("unhandledRejection", console.error); // prevent exit on error client.on("messageDelete", async (message) => { if (message.partial) return; // content is null or deleted embed snipes[message.channel.id] = { author: message.author.tag, content: message.content, embeds: message.embeds, attachments: [...message.attachments.values()].map((a) => a.proxyURL), createdAt: message.createdTimestamp, }; }); const snipe = snipes[channel.id]; if (!snipe) return interaction.editReply("There's nothing to snipe!"); const embed = new MessageEmbed() .setAuthor(snipe.author) .setFooter(`#${channel.name}`) .setTimestamp(snipe.createdAt); if (snipe.content) embed.setDescription(snipe.content); if (snipe.attachments.length) embed.setImage(snipe.attachments[0]); if (snipe.attachments.length || snipe.embeds.length) embed.addField( "Extra Info", `*Message also contained \`${snipe.embeds.length}\` embeds and \`${snipe.attachments.length}\` attachments.*` ); await interaction.editReply({ embeds: [embed] }); } catch (error) { console.log(error) } } }