0

代码:

const Discord = require('discord.js'), client = new Discord.Client();
const Canvas = require('canvas');

module.exports = {
    name: 'canvas',
async execute(m, args) {
const canvas = Canvas.createCanvas(762, 528);
const ctx = canvas.getContext('2d');
const background = await Canvas.loadImage('./background.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
function loadAndDrawImage(url)
{
    var image = new Canvas.Image();
    image.onload = function()
    {
      ctx.drawImage(image, 300, 300)
    }
    image.src = url;
}
loadAndDrawImage("http://www.w3.org/html/logo/img/mark-word-icon.png")
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), `picture.png`);
m.channel.send(attachment);
}}

当我执行生成图像的命令时,机器人给出的图像只有背景可见,而不是来自 w3.org
控制台的 HTML5 徽标没有给出任何错误..

4

1 回答 1

0

我认为您根本没有加载此图像,并且画布将为您提供默认的白色背景。它可以是 CORS。尝试在本地或您自己的服务器上使用相同的图像,也可以尝试 https

于 2020-10-03T13:48:14.823 回答