Hello, I was creating a discord bot using discord.js
So i was creating userVerifier which uses 4 layers of verification to verify users and check if they are safe or not and i was using canvas and nsfwjs to make sure users have apporpriate profile picture and nsfwjs need a proper file format and i use canvas for it but the problem is somewhere in const image = await loadImage(imageData); and it just frezzes there and doesn't continue .
Snippet
const avatarUrl = await member.user.displayAvatarURL({
size: 1024,
dynamic: false,
});
console.log(avatarUrl);
if (avatarUrl) {
//USER-VERIFIER LAYER 3
try {
const response = await axios.get(avatarUrl, {
responseType: "arraybuffer",
});
// Convert the response.data buffer to Uint8Array
const imageData = new Uint8Array(response.data);
// Convert the image to an HTMLImageElement-like object using node-canvas
const image = await loadImage(imageData);
const predictions = await nsfwModel.classify(image);
const nsfwProbability = predictions[0].probability["nsfw"];
if (nsfwProbability > 0.5) {
const embed2 = new EmbedBuilder()
.setTitle("Inpropriate Avatar Detected")
.setDescription(
"Our system has detected that your Avatar contains inpropriate image and you have been kicked, Please change your Avatar and join again"
)
.setColor("Red");
channel.send({
content: "New User Kicked",
embeds: [
LogEmbed.setDescription(
`\`TAG-${member.user.tag}, ID-${member.user.id}\` has been kicked from the server because the user's account contained inpropriate avatar`
),
],
});
member
.send({
content:
"*You have been kicked by the bot because our Advanced User-Verifier system has detected that your account contains inpropriate avatar*",
embeds: [embed2],
})
.then(() => {
member.kick({ Reason: "Kicked for inpropriate avatar" });
});
}
} catch (e) {
console.log(e);
}
}
Your Environment
Version of node-canvas (output of npm list canvas or yarn list canvas): "canvas": "^2.11.2",
Environment (e.g. node 4.2.0 on Mac OS X 10.8): Windows 11, v18.17.1
Packages:
Issue or Feature
Hello, I was creating a discord bot using discord.js So i was creating userVerifier which uses 4 layers of verification to verify users and check if they are safe or not and i was using canvas and nsfwjs to make sure users have apporpriate profile picture and nsfwjs need a proper file format and i use canvas for it but the problem is somewhere in
const image = await loadImage(imageData);
and it just frezzes there and doesn't continue .Snippet
Your Environment
npm list canvas
oryarn list canvas
): "canvas": "^2.11.2",