如何在 discord.js 节点 js 上发送图像?

How to send images on discord.js node js?

当我尝试让机器人不和谐时,我在从 url 发送图像时遇到问题,我收到消息“你好”,但没有图像。

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);

这就是你想要的写法...

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

虽然 files: 方法可能是错误的...如果这不起作用,请尝试此...

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

最好的方法是像 discord.js 那样使用 MessageAttachment。

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

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