From 144b4d4e60835dcb9e8bac6b92a1a27f5c8aafea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=A4KayJayDee?= Date: Sun, 19 Sep 2021 21:46:41 +0200 Subject: [PATCH] Added v13 example + example for embed --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 462d746..e17c336 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ const DIG = require("discord-image-generation"); Then you have to request your image and send it as an attachement. +## Discord.js v12 ```js // Import the discord.js library. const Discord = require("discord.js") @@ -57,6 +58,7 @@ bot.on("ready", () => { // Listen to the message event bot.on("message", async (message) => { + // Send the image in a simple message if (message.content === "*delete") { // Get the avatarUrl of the user let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); @@ -66,11 +68,70 @@ bot.on("message", async (message) => { let attach = new Discord.MessageAttachment(img, "delete.png");; message.channel.send(attach) } + // Send the message with the image attached to an embed + if (message.content === "*blur") { + // Get the avatarUrl of the user + let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); + // Make the image + let img = await new DIG.Blur().getImage(avatar) + // Add the image as an attachement + let embed = new Discord.MessageEmbed() + .setTitle("Blur") + .setImage("attachment://delete.png") + let attach = new Discord.MessageAttachment(img, "blur.png");; + message.channel.send({ embed: embed, files: [attach]) + } +}) + +// Log in to the bot +bot.login("super_secret_token") +``` + +## Discord.js v13 +```js +// Import the discord.js library. +const Discord = require("discord.js") +// Create a new discord.js client. +const bot = new Discord.Client() + +const DIG = require("discord-image-generation"); +> You can also destructure to avoid repeating DIG. + +// Listen to the ready event +bot.on("ready", () => { + console.log("ok"); +}) + +// Listen to the message event +bot.on("messageCreate", async (message) => { + // Send the image in a simple message + if (message.content === "*delete") { + // Get the avatarUrl of the user + let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); + // Make the image + let img = await new DIG.Delete().getImage(avatar) + // Add the image as an attachement + let attach = new Discord.MessageAttachment(img, "delete.png");; + message.channel.send({ files: [attach] }) + } + // Send the message with the image attached to an embed + if (message.content === "*blur") { + // Get the avatarUrl of the user + let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); + // Make the image + let img = await new DIG.Blur().getImage(avatar) + // Add the image as an attachement + let embed = new Discord.MessageEmbed() + .setTitle("Blur") + .setImage("attachment://delete.png") + let attach = new Discord.MessageAttachment(img, "blur.png");; + message.channel.send({ embeds: [embed], files: [attach]) + } }) // Log in to the bot bot.login("super_secret_token") -```` +``` # Available images diff --git a/package.json b/package.json index 78b0bb7..c4d3fae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord-image-generation", - "version": "1.4.9", + "version": "1.4.10", "description": "discord-image-generation is a powerfull module that allow you to generate awesome images.", "main": "src/index.js", "types": "typings/index.d.ts",