NodeJS 如何将图像附加到嵌入

flmtquvp  于 2023-06-29  发布在  Node.js
关注(0)|答案(2)|浏览(148)

我已经想了很久了。我不知道如何让机器人把图片附加到嵌入中。我正试图从我的电脑上传一张照片。

const commando = require('discord.js-commando');
const discord = require('discord.js')

class HoundCommand extends commando.Command {
  constructor(client) {
    super(client, {
      name: 'hound',
      group: 'simple',
      memberName: 'hound',
      description: 'Tells info about hound'
    });
  }

  async run(message, args) {
    var myInfo = new discord.RichEmbed()
      .setTitle("Hound")
      .addField("Name", "Hound")
      .addField("Age", "12")
      .addField("Description", "Im good at siege, I stream occasionally and ya")
      .setColor("#020B0C")
    message.channel.sendEmbed(myInfo);
  }
}

module.exports = HoundCommand;
6yoyoihd

6yoyoihd1#

既然你想从本地磁盘上传你的图像,你需要告诉Discord嵌入正是如此。每个嵌入都有一个.attachFile()方法,您可以从本地磁盘上传文件,并直接在嵌入中使用以下语法:attachment://fileName.extension
以avatar.png文件为例,您需要

var myInfo = new discord.RichEmbed()
  .setTitle("Hound")
  .addField("Name", "Hound")
  .addField("Age", "12")
  .addField("Description", "Im good at siege, I stream occasionally and ya")
  .setColor("#020B0C")
  .attachFile('./avatar.png')
  .setImage('attachment://avatar.png');
message.channel.sendEmbed(myInfo);

如果需要一次上载多个文件,请使用.attachFiles()方法。

kokeuurv

kokeuurv2#

discord.js v14中,我们有一种新的发送附件的方式。我们现在有了AttachmentBuilder,但代码更改应该很容易。只需从discord.js导入AttachmentBuilder即可

相关问题