From 7309779923f20dd4974f71bcb7645b0f6fe758cf Mon Sep 17 00:00:00 2001 From: skkeye <4247532@gmail.com> Date: Thu, 4 Jan 2024 20:50:50 -0500 Subject: [PATCH] init --- .gitignore | 1 + commands/emotes/stickerlog.js | 26 ++++++++++++++++++++++++++ events/interactionCreate.js | 3 +-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 commands/emotes/stickerlog.js diff --git a/.gitignore b/.gitignore index dc6e3c2..dabc6e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.json node_modules/ downloads/ +stickers/ \ No newline at end of file diff --git a/commands/emotes/stickerlog.js b/commands/emotes/stickerlog.js new file mode 100644 index 0000000..1d59520 --- /dev/null +++ b/commands/emotes/stickerlog.js @@ -0,0 +1,26 @@ +const { ContextMenuCommandBuilder, ApplicationCommandType, StickerFormatType } = require("discord.js"); +const fs = require('fs/promises'); + +module.exports = { + data : new ContextMenuCommandBuilder() + .setName("Sticker Log") + .setType(ApplicationCommandType.Message), + async execute(interaction) { + await interaction.deferReply(); + + const sticker = interaction.targetMessage.stickers.first(); + if (!sticker) { + await interaction.editReply("This message does not contain a sticker."); + return; + } + const link = sticker.url; + const copyname = sticker.name + "_FE"; + const response = await fetch(link); + const extension = (sticker.format == StickerFormatType.PNG) ? ".png" : + (sticker.format == StickerFormatType.APNG) ? ".apng" : + (sticker.format == StickerFormatType.LOTTIE) ? ".json" : ".webp"; + // save the file + await fs.writeFile(`./stickers/${copyname}${extension}`, response.body); + await interaction.editReply(`Dowloaded ${sticker.name}!\n`); + } +} \ No newline at end of file diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 7d241b8..783d216 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -3,7 +3,6 @@ const { Events } = require('discord.js'); module.exports = { name: Events.InteractionCreate, async execute(interaction) { - if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); @@ -11,7 +10,7 @@ module.exports = { console.error(`No command matching ${interaction.commandName} was found.`); return; } - + try { await command.execute(interaction); } catch (error) {