Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Bot not sending Canvas - discord.js

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

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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",
});
about 4 years ago · Santiago Trujillo Report

0

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'
        });

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!