【问题标题】:How to attach an image to an embed如何将图像附加到嵌入
【发布时间】:2019-06-01 17:27:10
【问题描述】:

我一直在尝试解决这个问题。 我不知道如何让机器人将图像附加到嵌入中。 我正在尝试从我的电脑上传图片。

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;

【问题讨论】:

  • 您能详细说明一下吗?在哪里附上图片?在嵌入下?在嵌入?哪个领域和地点?
  • 在嵌入中,在描述下

标签: javascript node.js discord.js


【解决方案1】:

由于您希望从本地磁盘上传图像,因此您需要准确地告诉 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() 方法。

【讨论】:

    猜你喜欢
    • 2021-08-13
    • 2020-10-03
    • 1970-01-01
    • 2011-03-17
    • 2014-08-15
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多