const Discord = require("discord.js"); const Jimp = require("jimp"); const client = new Discord.Client(); client.on("ready", async () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on("message", async (message) => { if (message.author.bot) return; const imageTemp = "https://upload.wikimedia.org/wikipedia/commons/8/8a/Banana-Single.jpg"; const messageAttachment = message.attachments.size > 0 ? message.attachments.array()[0].url : null; // Exit if there is no message attachment present in the message if (!messageAttachment) return; // Resolve the temporary image url to Jimp object const firstImage = await Jimp.read(imageTemp); // Resolve the message attachment image url to Jimp object const secondImage = await Jimp.read(messageAttachment); // Composite the two images together (modifies the firstImage object) firstImage.composite(secondImage, 10, 10); // Save the resulting image to buffer const buffer = await firstImage.getBufferAsync(Jimp.MIME_JPEG); // Send the buffer as a message attachment message.channel.send("Combined image:", {files: [{ attachment: buffer }]}); }); client.login("...");