Discord.js(还上传附件图像并直接获取此attchemend的URL)

时间:2019-09-28 13:41:00

标签: discord.js

我需要帮助。

我要在Discord中上传图片,上传完成后,我会自动将其发布到嵌入文件中。 这可能吗?

1 个答案:

答案 0 :(得分:0)

您可以在丰富的嵌入中使用附件,而不必单独发送附件。

  1. 使用Attachment类构造函数创建附件。您可以使用缓冲区,本地路径,URL或流来生成文件。

  2. 照常构造您的RichEmbed。可以在嵌入中使用以下语法引用附件:attachment://<filename>

  3. 通过使用TextBasedChannel.send()options参数,您可以发送附件嵌入。

请考虑以下代码,该代码发送带有Discord徽标的丰富嵌入内容作为图像...

const { Attachment, RichEmbed } = require('discord.js');

const attachment = new Attachment('https://discordapp.com/assets/fc0b01fe10a0b8c602fb0106d8189d9b.png', 'Discord.png');
const files = [attachment];

const embed = new RichEmbed()
  .setColor('#7289DA')
  .setImage('attachment://Discord.png');

/* TextBasedChannel */.send({ embed, files })
  .catch(console.error);