const { Sticker, StickerTypes } = require("wa-sticker-formatter");
const { MessageMedia } = require("whatsapp-web.js");
const isImageURL = require('image-url-validator').default;
const axios = require('axios');
module.exports = {
name: sticker,
description: Make a sticker with the provided image \n Usage:,
cooldown: 3000,
run: async (client, message, args) => {
try{
//declare variables
const chat = await message.getChat();
let imgdata;
let finishbuffer;
let attachment;
if(!message.hasMedia && !args[1]) return message.reply("Please attach an image or provide a url link of a image")
if(message.hasMedia && args[1]) return message.reply("Please only choose to use image link\nor attach an image to the bot")
if(!args[0]) return message.reply(`Please give me a name for the sticker use ?sticker {Name} [url] \n use (-) to add space \n*example:* ?sticker hello-there https://media.tenor.com/6Dy8bQJuB3YAAAAC/falling-bread-bread.gif`)
const name = args[0].toString().replaceAll("-", " ");
if(message.hasMedia){
imgdata = await message.downloadMedia()
attachment = Buffer.from(imgdata.data, "base64")
}else{
const urlcheck = await isImageURL(args[1].toString().trimEnd())
if(urlcheck === false) {
return message.reply("The url is not a valid image url")
}else{
const response = await axios(args[1].toString().trimEnd(), { responseType: 'arraybuffer' })
attachment = Buffer.from(response.data, "ArrayBuffer")
}
}
finishbuffer = await new Sticker(
attachment,
)
.setPack(name || "No name " + Math.floor(Math.random() * 100000000000) + 1)
.setAuthor(message._data.notifyName || "gamers_indo1223")
.setType(StickerTypes.CROPPED)
.setCategories(["🎉"])
.setID(Math.floor(Math.random() * 100000000000) + 1)
.setQuality(100)
.toBuffer();
console.log(`1-${typeof attachment}`)
console.log(`2-${Buffer.isBuffer(attachment)}`)
console.log(`3-${Buffer.byteLength(attachment)}`)
await chat.sendMessage(
new MessageMedia(
"image/webp",
Buffer.from(finishbuffer).toString("base64")),
{ sendMediaAsSticker: true }
);
}catch(e){
console.log(e)
return message.reply("An Error has occurred, maybe you put not a image url\nError Message: " + e.message)
}
},
};
Browser Type
Google Chrome
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
OS: WIn 11
phone OS: bluestacks
wwebjs: latest
whatsapp web ver: 2.2247.7
nodejs ver 18
Is there an existing issue for this?
Describe the bug
This bug happened after i tried to convert a gif from tenor this bug didn't happened if i attach an image/video/gif
Expected behavior
As a user, i expected the bot to give me the converted sticker
Steps to Reproduce the Bug or Issue
Use any tenor gif like https://media.tenor.com/6Dy8bQJuB3YAAAAC/falling-bread-bread.gif the bot will give a sticker of the giv
Relevant Code
const { Sticker, StickerTypes } = require("wa-sticker-formatter"); const { MessageMedia } = require("whatsapp-web.js"); const isImageURL = require('image-url-validator').default; const axios = require('axios'); module.exports = { name:
sticker
, description:Make a sticker with the provided image \n Usage:
, cooldown: 3000, run: async (client, message, args) => { try{ //declare variables const chat = await message.getChat(); let imgdata; let finishbuffer; let attachment;}, };
Browser Type
Google Chrome
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
Yes, I am using Multi Device
Environment
OS: WIn 11 phone OS: bluestacks wwebjs: latest whatsapp web ver: 2.2247.7 nodejs ver 18
Additional context
No response