Ask coding questions

← Back to all posts
Fontconfig error: Cannot load default config file Node.js Canvas
SrTecc

Hi, I saw this condition in an Ultrax video, however the code is not working, it should send a welcome image when someone new enters the server, can someone help me fix the code?

`const { registerFont, createCanvas } = require('canvas')
registerFont('./font/OpenSans-Bold.ttf', { family: 'Open Sans' })
const canvas = createCanvas(500, 500)
const Canvas = require('canvas');

var welcomeCanvas = {};
welcomeCanvas.create = Canvas.createCanvas(1024, 500)
welcomeCanvas.context = welcomeCanvas.create.getContext('2d')
welcomeCanvas.context.font = '72px OpenSans-Bold';
welcomeCanvas.context.fillStyle = '#ffffff';

Canvas.loadImage("./img/Teste.png").then(async (img) => {
welcomeCanvas.context.drawImage(img, 0, 0, 1024, 500)
welcomeCanvas.context.fillText("Testando boas vindas", 360, 360);
welcomeCanvas.context.beginPath();
welcomeCanvas.context.arc(512, 166, 128, 0, Math.PI * 2, true);
welcomeCanvas.context.stroke()
welcomeCanvas.context.fill()
})

require('ultrax').inviteLogger(client)

client.on('guildMemberAdd', async member => {
const welcomechannel = Client.channels.cache.get('794293128600879125')
let canvas = welcomeCanvas;
canvas.context.font = '42px OpenSans-Bold';
canvas.context.textAling = 'center';
canvas.context.fillText(member.user.tag.toUpperCase(), 512, 410)
canvas.context.font = '32px OpenSans-Bold';
canvas.context.fillText(Você é o ${member.guild.memberCount} Tenno em nosso servidor, 512, 455)
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 atta = new Discord.MessageAttachment(canvas.create.toBuffer(), Bem vindo ${member.id}.png)
try {
welcomechannel.send(Olá Tenno ${member}, bem vindo ao ${member.guild.name}!, atta)
} catch (error) {
console.log(error)
}
});`

Voters
SrTecc