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

303
Visualizações
send an image using discord.js

I have been following a few different guides to program a simple discord bot. Everything works except I cannot get it to send an image. I have looked at these previous questions 1 2, but their solutions are not working for me. This is my code:

const {Client, Intents} = require('discord.js');

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = '?';

client.once('ready', () => {
  console.log("Dog is online!");
});

client.on('messageCreate', message => {
  if(!message.content.startsWith(prefix) || message.author.bot) return;

  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();

  if(command === 'ping') {
    message.channel.send('pong!');
  }
  else if (command === 'bark') {
    message.channel.send('bark bark bark grrrr...')
  }
  else if(command === 'nick') {
    message.channel.send('grrr...');
  }
  else if (command === 'pic') {
    message.channel.send("little dog", {files: ["https://i.imgur.com/xxXXXxx.jpeg"] });
  }

});

//must be last line
client.login('');

my client login is there in my editor, just not sharing it here. the "pic" command is what is not working. It displays the "little dog" text, but does not send the image. The only reason I'm using imgur is because I'm not sure if you can send local images; if someone knows a solution using local files I'll take it.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use

files: [{ attachment: "YourImage.jpg" }] });

You can also rename the image with

files: [{ attachment: <images>.toBuffer(), name: 'newName.png' }] });

Example:

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

the <images> is your image variable

const images = blablabla
about 4 years ago · Juan Pablo Isaza Relatório

0

According to the V13 discord.js

You can do following, this is also working for me.

const { MessageAttachment } = require('discord.js')

const attachment = new MessageAttachment('URL'); //ex. https://i.imgur.com/random.jpg

message.channel.send({ content: "I sent you a photo!", files: [attachment] })

This example will send a photo with the text I sent you a photo!

about 4 years ago · Juan Pablo Isaza 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