Untitled

 avatar
unknown
plain_text
2 years ago
2.0 kB
2
Indexable
if (interaction.commandName == "canavas"){
        const canvas = Canvas.createCanvas(700, 250);
		const context = canvas.getContext('2d');

        const background = await Canvas.loadImage('./canva.png');

        // This uses the canvas dimensions to stretch the image onto the entire canvas
        context.drawImage(background, 0, 0, canvas.width, canvas.height);

        context.strokeStyle = '#0099ff';

        // Draw a rectangle with the dimensions of the entire canvas
        context.strokeRect(0, 0, canvas.width, canvas.height);

        // Select the font size and type from one of the natively available fonts
        context.font = '60px';

        // Select the style that will be used to fill the text in
        context.fillStyle = '#ffffff';

        // Actually fill the text with a solid color
        context.fillText(interaction.member.displayName, canvas.width / 2.5, canvas.height / 1.8);

        // Pick up the pen
        context.beginPath();

        // Start the arc to form a circle
        context.arc(125, 125, 100, 0, Math.PI * 2, true);
        
        // Put the pen down
        context.closePath();
        
        // Clip off the region you drew on
        context.clip();

        const { body } = await request(interaction.user.displayAvatarURL({ extension: 'jpg' }));
        const avatar = await Canvas.loadImage(await body.arrayBuffer());
    
        // If you don't care about the performance of HTTP requests, you can instead load the avatar using
        // const avatar = await Canvas.loadImage(interaction.user.displayAvatarURL({ extension: 'jpg' }));
    
        // Draw a shape onto the main canvas
        context.drawImage(avatar, 25, 25, 200, 200);



        // Use the helpful Attachment class structure to process the file for you
        const attachment = new AttachmentBuilder(await canvas.encode('png'), { name: 'profile-image.png' });
    
        interaction.reply({ files: [attachment] });
    }