【问题标题】:Not able to display local Image in embed? Discord.js无法在嵌入中显示本地图像?不和谐.js
【发布时间】:2020-10-17 13:22:27
【问题描述】:

我尝试了很多方法来让照片在嵌入中工作,但我做不到。它总是不显示图像,我不知道为什么。

我有一个函数可以生成一个随机名称,然后将文件保存到一个名为“Images”的文件夹中 然后我尝试使用嵌入中的路径显示该图像,但它不起作用。 删除了大量代码,因此更易于使用。

var RandomId = "Images/" + MakeId(16) + ".png"
var FileName = RandomId.replace("Images/", "")

//writefile stuff here that makes file

const attachment = new Discord.MessageAttachment(RandomId , FileName);
const ExampleCommand = new Discord.MessageEmbed()
     .setColor("#21BA45")
    .setTitle(CommandTitle.content)
    .setDescription(CommandDescription.content)
    .addField(CommandMediaDescription, "-")
    .setImage("attachment://" + FileName)
Channel.send(ExampleCommand)

显示它已创建并保存的图像

【问题讨论】:

标签: node.js discord.js


【解决方案1】:

我不建议在 javascript 中使用 PascalCase,除非用于类,因为它会让你自己和其他开发者感到困惑,正如 sytnax 突出显示的那样,

无论如何,问题是您没有附加附件:

ExampleCommand
   .attachFiles(attachment)
   .setColor("#21BA45")
   .setTitle(CommandTitle.content)
   .setDescription(CommandDescription.content)
   .addField(CommandMediaDescription, "-")
   .setImage("attachment://" + FileName);

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 2021-12-01
    • 2021-05-14
    • 2020-11-12
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 2021-12-17
    相关资源
    最近更新 更多