我有用于反转图像的代码。由于没有教程,因此我尝试按照教程片段来整理命令。
我记录了图像,并且显示正常。当我运行命令时,也没有错误,但是图像没有显示。
module.exports = {
name: "invert",
description: "Invert your avatar image",
async execute(message, member) {
const Canvas = require("canvas");
const Discord = require("discord.js");
let theCanvas = Canvas.createCanvas(218, 218);
const ctx = theCanvas.getContext("2d");
const theAvatar = await Canvas.loadImage(message.member.user.displayAvatarURL);
console.log(theAvatar);
var imageData = ctx.getImageData(0, 0, theAvatar.width, theAvatar.height);
for (var i = 0; imageData.data.length; i += 4) {
imageData.data[i] = 255 - imageData.data[i];
imageData.data[i + 1] = 255 - imageData.data[i + 1];
imageData.data[i + 2] = 255 - imageData.data[i + 2];
imageData.data[i + 3] = 255;
}
console.log(imageData);
const attachment = new Discord.Attachment(imageData.toBuffer());
message.channel.send(attachment);
},
};
答案 0 :(得分:0)
我显示图像的方式要简单得多。
client.on("message", message => {
if (message.content.startsWith("?" + "avatar")) {
message.reply(message.author.displayAvatarURL());
}
});
我认为问题可能出在您说const theAvatar = await Canvas.loadImage(message.member.user.displayAvatarURL);