【发布时间】:2019-06-19 08:14:13
【问题描述】:
我在尝试使用 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 重定向的重定向而不是返回该错误?
【问题讨论】:
标签: javascript node.js canvas node-canvas