Hey!
I made a bot with canvas and Discord.js v13 that automatically writes a welcome message.
This works so far without any problems. But if a second user joins the server, only the profile picture and not the name will be updated.
How could I fix this? Thank you for your help!
Here is my code that I'm using and some sample images. (please ignore the wrong formatting ^^)
Link to images: https://imgur.com/a/h4NIgGC
const Discord = require("discord.js")
const Canvas = require("canvas")
bot.on("guildMemberAdd", async (member) => {
var welcomeCanvas = {};
welcomeCanvas.create = Canvas.createCanvas(1024, 500)
welcomeCanvas.context = welcomeCanvas.create.getContext("2d")
welcomeCanvas.context.font = 'bold 72px Arial';
welcomeCanvas.context.fillStyle = "#ffffff";
Canvas.loadImage("https://www.misspompadour.de/media/cb/23/bb/1635526572/painting-the-past-persian-grey-kreidefarbe-farbe-wand-ansicht.jpg").then(async (img) => {
welcomeCanvas.context.drawImage(img, 0, 0, 1024, 500)
welcomeCanvas.context.fillText("WELCOME", 260, 360);
welcomeCanvas.context.beginPath();
welcomeCanvas.context.arc(512, 166, 128, 0, Math.PI * 2, true);
welcomeCanvas.context.stroke();
welcomeCanvas.context.fill()
})
const welcomechannel = bot.channels.cache.get("913099401721950259")
let canvas = welcomeCanvas;
canvas.context.font = " bold 42px Arial";
canvas.context.textAlign = "center";
canvas.context.fillText(member.user.tag.toLocaleUpperCase(), 512, 415)
canvas.context.font = "bold 32px Arial";
canvas.context.fillText(`WE ARE NOW ${member.guild.memberCount} MEMBERS`, 512, 465)
canvas.context.beginPath();
canvas.context.arc(512, 166, 119, 0, Math.PI * 2, true)
canvas.context.closePath()
canvas.context.clip()
await Canvas.loadImage(member.user.displayAvatarURL({ format: 'png', size: 1024 }))
.then(img => {
canvas.context.drawImage(img, 393, 47, 238, 238);
})
let attachment = new Discord.MessageAttachment(canvas.create.toBuffer(), `welcome-${member.user.id}.png`)
welcomechannel.send({ files: [attachment] });
}