Files
emot_man/bot/commands/emotes/stickerlog.js

27 lines
1.1 KiB
JavaScript

const { ContextMenuCommandBuilder, ApplicationCommandType, StickerFormatType } = require("discord.js");
const fs = require('fs/promises');
const { STICKER_DIR } = process.env;
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(`${STICKER_DIR}${copyname}${extension}`, response.body);
await interaction.editReply(`Dowloaded ${sticker.name}!\n`);
}
}