我总是得到错误“错误:当试图使用loadImage()函数时,服务器响应为301”。
我在函数中提供的URL从http重定向到https,但是函数没有遵循重定向,而是返回了该错误。
async run(msg, { item }) {
const canvas = Canvas.createCanvas(330, item.height);
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgb(54, 57,62)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
const iconImg = await Canvas.loadImage(item.icon); // <---
ctx.drawImage(iconImg, 0, 0);
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'image.png');
msg.channel.send(attachment);
}是否有任何方法使该函数跟踪301重定向而不是返回该错误?
发布于 2019-04-22 23:36:48
这将在下一个版本(https://github.com/Automattic/node-canvas/pull/1398) - 2.4.2或2.5.0中得到修正。
在此之前,您必须手动发出HTTP请求并遵循重定向。
https://stackoverflow.com/questions/54366205
复制相似问题