Bot not sending Canvas - discord.js

Viewed 145

I'm doing a testing bot in discord.js that sends profile cards when the $profile command is called. But i have zero experience with Canvas so I googled some tutorials and followed them

But the problem is that the bot doesn't send the attachment, I've tried to research other ways to do that but they don't work either

This is the code of the canvas

const Canvas = require('canvas')
const Discord = require("discord.js");

module.exports =
{
    name: 'profile',
    description: '',
    run: async (client, message) =>
        {
            const profilecanvas = Canvas.createCanvas(660,315)
            const ctx = profilecanvas.getContext('2d')
            const bg = await Canvas.loadImage('https://i.imgur.com/______.png')

            ctx.drawImage(bg, 0, 0, profilecanvas.width, profilecanvas.height);
            ctx.strokeStyle = '#fdfd34';
            ctx.strokeRect(0, 0, profilecanvas.width, profilecanvas.height);

            const attachment = new Discord.MessageAttachment(profilecanvas.toBuffer(), bg);

            message.channel.send('testing', attachment)
        }
    }

And it sends the "testing" normally, only the Canvas is not sent and no syntax error appears in the terminal

2 Answers

Try passing a MessageOptions type parameter, with an attachments property whose value is an array with your attachment as its only element, and a content property of value "testing":

message.channel.send({
    attachments: [attachment],
    content: "testing",
});

use

message.channel.send({files: [attachment]});

and if you want to have a picture and text in one message then

        message.channel.send({
            files: [attachment],
            content: 'Message text'
        });

Related