Update examples

main
Mr¤KayJayDee 2 years ago
parent f67b6466e7
commit 5830a76096

@ -18,10 +18,10 @@ Please join [this](https://discord.gg/5ZSGFYtnqw) community server to follow all
# Links: # Links:
### Support Server Community ### Support Server Community
<a href="https://discord.gg/5ZSGFYtnqw"><img src="https://discord.com/api/guilds/833309512412299276/widget.png" alt="Amandine support server"/></a> <a href="https://discord.gg/5ZSGFYtnqw"><img src="https://discord.com/api/guilds/833309512412299276/widget.png" alt="Coding support server"/></a>
### Amandine Discord Bot Support Server ### Xinko Discord Bot Support Server
<a href="https://discord.gg/Uqd2sQP"><img src="https://discord.com/api/guilds/527836578912010251/widget.png" alt="Amandine support server"/></a> <a href="https://discord.gg/Uqd2sQP"><img src="https://discord.com/api/guilds/527836578912010251/widget.png" alt="Xinko support server"/></a>
# Download # Download
@ -41,96 +41,123 @@ const DIG = require("discord-image-generation");
Then you have to request your image and send it as an attachement. Then you have to request your image and send it as an attachement.
## Discord.js v12 ## Discord.js v13
```js ```js
// Import the discord.js library. // Import the discord.js library.
const Discord = require("discord.js") const Discord = require("discord.js");
// Create a new discord.js client. // Create a new discord.js client.
const bot = new Discord.Client() const bot = new Discord.Client();
const DIG = require("discord-image-generation"); const DIG = require("discord-image-generation");
> You can also destructure to avoid repeating DIG.
// Listen to the ready event // Listen to the ready event
bot.on("ready", () => { bot.on("ready", () => {
console.log("ok"); console.log("Bot is online");
}) });
// Listen to the message event // Listen to the message event
bot.on("message", async (message) => { bot.on("messageCreate", async (message) => {
// Send the image in a simple message // Send the image in a simple message
if (message.content === "*delete") { if (message.content === "*delete") {
// Get the avatarUrl of the user // Get the avatarUrl of the user
let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); let avatar = message.author.displayAvatarURL({
dynamic: false,
format: 'png'
});
// Make the image // Make the image
let img = await new DIG.Delete().getImage(avatar) let img = await new DIG.Delete().getImage(avatar);
// Add the image as an attachement // Add the image as an attachement
let attach = new Discord.MessageAttachment(img, "delete.png");; let attach = new Discord.MessageAttachment(img, "delete.png");
message.channel.send(attach) message.channel.send({
files: [attach]
});
} }
// Send the message with the image attached to an embed // Send the message with the image attached to an embed
if (message.content === "*blur") { if (message.content === "*blur") {
// Get the avatarUrl of the user // Get the avatarUrl of the user
let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); let avatar = message.author.displayAvatarURL({
dynamic: false,
format: 'png'
});
// Make the image // Make the image
let img = await new DIG.Blur().getImage(avatar) let img = await new DIG.Blur().getImage(avatar);
// Add the image as an attachement // Add the image as an attachement
let embed = new Discord.MessageEmbed() let embed = new Discord.MessageEmbed()
.setTitle("Blur") .setTitle("Blur")
.setImage("attachment://delete.png") .setImage("attachment://delete.png");
let attach = new Discord.MessageAttachment(img, "blur.png");; let attach = new Discord.MessageAttachment(img, "blur.png");
message.channel.send({ embed: embed, files: [attach]) message.channel.send({
embeds: [embed],
files: [attach]
});
} }
}) });
// Log in to the bot // Log in to the bot
bot.login("super_secret_token") bot.login("super_secret_token");
``` ```
## Discord.js v13 ## Discord.js v14
```js ```js
// Import the discord.js library. // Import the required elements from the discord.js library.
const Discord = require("discord.js") const { Client, GatewayIntentBits, AttachmentBuilder, EmbedBuilder } = require("discord.js");
// Create a new discord.js client. // Create a new discord.js client.
const bot = new Discord.Client() const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const DIG = require("discord-image-generation"); const DIG = require("discord-image-generation");
> You can also destructure to avoid repeating DIG.
// Listen to the ready event // Listen to the ready event
bot.on("ready", () => { bot.on("ready", () => {
console.log("ok"); console.log("Bot is online");
}) });
// Listen to the message event // Listen to the message event
bot.on("messageCreate", async (message) => { bot.on("messageCreate", async (message) => {
// Send the image in a simple message // Send the image in a simple message
if (message.content === "*delete") { if (message.content === "*delete") {
// Get the avatarUrl of the user // Get the avatarUrl of the user
let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); let avatar = message.author.displayAvatarURL({
forceStatic: true,
extension: 'png'
});
// Make the image // Make the image
let img = await new DIG.Delete().getImage(avatar) let img = await new DIG.Delete().getImage(avatar);
// Add the image as an attachement // Add the image as an attachement
let attach = new Discord.MessageAttachment(img, "delete.png");; let attach = new AttachmentBuilder(img).setName("delete.png");
message.channel.send({ files: [attach] }) message.channel.send({
files: [attach]
});
} }
// Send the message with the image attached to an embed // Send the message with the image attached to an embed
if (message.content === "*blur") { if (message.content === "*blur") {
// Get the avatarUrl of the user // Get the avatarUrl of the user
let avatar = message.author.displayAvatarURL({ dynamic: false, format: 'png' }); let avatar = message.author.displayAvatarURL({
forceStatic: true,
extension: 'png'
});
// Make the image // Make the image
let img = await new DIG.Blur().getImage(avatar) let img = await new DIG.Blur().getImage(avatar);
// Add the image as an attachement // Add the image as an attachement
let embed = new Discord.MessageEmbed() let embed = new EmbedBuilder()
.setTitle("Blur") .setTitle("Blur")
.setImage("attachment://delete.png") .setImage("attachment://blur.png");
let attach = new Discord.MessageAttachment(img, "blur.png");; let attach = new AttachmentBuilder(img).setName("blur.png");
message.channel.send({ embeds: [embed], files: [attach]) message.channel.send({
embeds: [embed],
files: [attach]
});
} }
}) });
// Log in to the bot // Log in to the bot
bot.login("super_secret_token") bot.login("super_secret_token");
``` ```
# Available images # Available images
@ -209,7 +236,7 @@ bot.login("super_secret_token")
- ``new DIG.Deepfry().getImage(`<Avatar>`);`` - ``new DIG.Deepfry().getImage(`<Avatar>`);``
![Deepfry](https://imgur.com/beAiPNv.png) ![Deepfry](https://imgur.com/q2ADecK.png)
- ``new DIG.Delete().getImage(`<Avatar>`);`` - ``new DIG.Delete().getImage(`<Avatar>`);``
@ -327,6 +354,10 @@ bot.login("super_secret_token")
# Changelog # Changelog
## v1.4.21
- Added discord.js V14 usage example
- Removed discord.js V12 usage example
## v1.4.20 ## v1.4.20
- Some fixes - Some fixes
- Added Clown() (thanks to Retrojection#1937) - Added Clown() (thanks to Retrojection#1937)

@ -1,6 +1,6 @@
{ {
"name": "discord-image-generation", "name": "discord-image-generation",
"version": "1.4.20", "version": "1.4.21",
"description": "discord-image-generation is a powerful module that allow you to generate awesome images.", "description": "discord-image-generation is a powerful module that allow you to generate awesome images.",
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {

@ -4,7 +4,7 @@ const { validateURL } = require(`../functions`);
module.exports = class Deepfry { module.exports = class Deepfry {
async getImage(image) { async getImage(image) {
if (!image) throw new Error(`You must provide an image as a first argument.`); if (!image) throw new Error(`You must provide an image as a first argument.`);
let isValid = await validateURL(img1); let isValid = await validateURL(image);
if (!isValid) return console.error(`You must provide a valid image URL or buffer.`); if (!isValid) return console.error(`You must provide a valid image URL or buffer.`);
image = await jimp.read(image); image = await jimp.read(image);
image.resize(500, 500); image.resize(500, 500);

Loading…
Cancel
Save