Home > other >  How to send images on discord.js node js?
How to send images on discord.js node js?

Time:05-25

i have problem with sending images from url when i try to make bot discord, i got the messages " Hello " but not with the images.

require('dotenv').config();
const Discord = require("discord.js");
const client = new Discord.Client({intents: ["GUILDS", "GUILD_MESSAGES"]});
client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`)
})


client.on("message", msg => {
  if (msg.content === "p") {
    msg.reply("Hello", {files: ["https://s.imgur.com/images/logo-1200-630.jpg?2"]});
  }
})

client.login(process.env.DISCORD_TOKEN);

CodePudding user response:

this is how you want to write it...

msg.reply("Hello",
{ files: [
{attachment: "https://s.imgur.com/images/logo-1200-630.jpg?2", name: "image.jpg"},
]});

the files: approach may be wrong though... if that doesn't work try this...

msg.reply("Hello https://s.imgur.com/images/logo-1200-630.jpg?2");

CodePudding user response:

The best way is to use MessageAttachment like discord.js intended.

const image = new Discord.MessageAttachment("https://s.imgur.com/images/logo-1200-630.jpg?2","img.png");

msg.reply({ files : [image] })
  • Related