Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda