Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errore: tipo di immagine non supportato #2346

Open
AFDavi06 opened this issue Feb 11, 2024 · 0 comments
Open

Errore: tipo di immagine non supportato #2346

AFDavi06 opened this issue Feb 11, 2024 · 0 comments

Comments

@AFDavi06
Copy link

`const Discord = require("discord.js")
const client = new Discord.Client({ intents: Object.values(Discord.IntentsBitField.Flags)})

client.once("ready", () => {
console.log(Logged in as ${client.user.tag}!);
console.log(client.user.tag)
});
client.login("token")

const { createCanvas, loadImage, MessageAttachment } = require('canvas');

client.on('guildMemberAdd', async (member) => {
const welcomeChannel = client.channels.cache.get('1188962541842485353');
const rulesChannel = client.channels.cache.get('1192109584777760868');
const verifyChannel = client.channels.cache.get('1193611427450200078');
const infoChannel = client.channels.cache.get('1192102711718596688');

if (welcomeChannel && rulesChannel && verifyChannel && infoChannel) {
console.log("Sto per inviare il messaggio di benvenuto a:", member.user.tag);

const canvas = createCanvas(1024, 500);
const ctx = canvas.getContext('2d');

const background = await loadImage("/static(1).png").catch(error => {
  console.error("Errore nel caricamento dell'immagine:", error);
});



if (background) {
  ctx.drawImage(background, 0, 0, canvas.width, canvas.height);

  ctx.font = '72px sans-serif';
  ctx.fillStyle = '#ffffff';
  ctx.fillText('Welcome', 360, 360);

  ctx.beginPath();
  ctx.arc(512, 166, 128, 0, Math.PI * 2, true);
  ctx.stroke();
  ctx.fill();

  ctx.font = '42px sans-serif';
  ctx.textAlign = 'center';
  ctx.fillText(member.user.tag.toUpperCase(), 512, 410);
  ctx.font = '32px sans-serif';
  ctx.fillText(`You are the ${member.guild.memberCount}th`, 512, 455);

  ctx.beginPath();
  ctx.arc(512, 166, 119, 0, Math.PI * 2, true);
  ctx.closePath();
  ctx.clip();

  const avatar = await loadImage(member.user.displayAvatarURL({ format: 'png', size: 1024 }));
  ctx.drawImage(avatar, 393, 47, 238, 238);

  const attachment = new MessageAttachment(canvas.toBuffer(), `welcome-${member.id}.png`);
  
  try {
    welcomeChannel.send(`:wave: Hello ${member}, welcome to ${member.guild.name}!`, { files: [attachment] });
    welcomeChannel.send(`Don't forget to read the rules in ${rulesChannel} and verify yourself in ${verifyChannel}. For more information, check out ${infoChannel}.`);
    
  
    console.log("Messaggio di benvenuto inviato con successo a:", member.user.tag);
  } catch (error) {
    console.error("Errore nell'invio del messaggio di benvenuto", error);
  }
}

}
});
`
node:events:497
throw er; // Unhandled 'error' event
^

Error: Unsupported image type
at setSource (C:\Users\Utente\Desktop\DS\node_modules\canvas\lib\image.js:94:13)
at C:\Users\Utente\Desktop\DS\node_modules\canvas\lib\image.js:62:11
at C:\Users\Utente\Desktop\DS\node_modules\simple-get\index.js:97:7
at IncomingMessage. (C:\Users\Utente\Desktop\DS\node_modules\simple-concat\index.js:8:13)
at Object.onceWrapper (node:events:633:28)
at IncomingMessage.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1696:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21)

Node.js v21.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant