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

295
Views
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 answers
Answer question

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 Report

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 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!