1

como eu poderia mandar a imagem para o discord sem ter esse erro

var Canvas = require('canvas')
  , Image = Canvas.Image

var Discord = require('discord.js')
  , isla = new Discord.Client();

var server = require(__dirname + '/server.js');

var request = require('request');
var fs = require('fs');

var background = new Image();
background.src = "Fundo.png";
var post = new Image();
post.src = "Pos.png";
var x = 0;




console.log(x);
isla.on('message',(msg) =>{
    if(msg == "<test"){
msg.channel.startTyping(10);

  canvas = new Canvas(450,450);
  ctx = canvas.getContext('2d');
   var requestSettings = {
    url: msg.author.avatarURL,
    method: 'GET',
    encoding: null
  };
   request.get(requestSettings, 
    function(err, result, body) {
         ctx.drawImage(new Image(result),0,0); 
  })


  ctx.font = '27px Century Gothic';
  ctx.drawImage(background,0,0); 
  ctx.drawImage(post,0,0); 
  ctx.fillText(msg.author.username, 12, 300);
  var te = ctx.measureText(msg.author.username);
  ctx.strokeStyle = 'rgba(0,0,0,0.5)';
  ctx.beginPath();
  msg.channel.sendFile(canvas.toBuffer());
  console.log("teste")
  msg.channel.stopTyping(true);
}
});

Quando uso NODE . ele da o seguinte erro

C:\Users\Yatogamix\Desktop\Giftias\isla\main.js:36
         ctx.drawImage(new Image(body),0,0);
             ^

Error: Image given has not completed loading
    at Request._callback (C:\Users\Yatogamix\Desktop\Giftias\isla\main.js:36:18)
at Request.self.callback (C:\Users\Yatogamix\Desktop\Giftias\isla\node_modules\request\request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:194:7)
at Request.<anonymous> (C:\Users\Yatogamix\Desktop\Giftias\isla\node_modules\request\request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:191:7)
at IncomingMessage.<anonymous> (C:\Users\Yatogamix\Desktop\Giftias\isla\node_modules\request\request.js:1091:12)
at Object.onceWrapper (events.js:293:19)
at emitNone (events.js:91:20)

0

Você deve fazer log-in para responder a esta pergunta.

Pesquise outras perguntas com a tag .