Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda