代码:
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 徽标没有给出任何错误..