【问题标题】:Why won't my Discord.js image files load well?为什么我的 Discord.js 图像文件加载不好?
【发布时间】:2021-12-08 17:50:09
【问题描述】:

当我将 Discord 附件中的 .png 图像文件下载到我的机器人(由 Replit 托管)时,该图像不会出现在我的文件中。我有 Node v12.16.1,将图像直接导入我的 Replit 文件没有问题。当我尝试在 Replit 上下载它时,我的 Mac 说文件无法打开,所以我知道它没有正确保存。如何让它正确下载?

client.on("message" , msg => {

  if (msg.content === "$Time") {
    msg.attachments.forEach(a => {
    {fs.writeFileSync(`./${a.name}`, a.png); 
   }}) 
    
   var interval = setTimeout (function () { msg.channel.send("Sure thing", {files: [`./images/SPOILER_HW.png`]})
       // use the message's channel (TextChannel) to send a new message
       //.catch(console.error);
   },  5000);
  }    
})

How the image appears on Replit

【问题讨论】:

    标签: file-upload discord.js writefile


    【解决方案1】:

    关于这一点,是的,replit 是一个处理代码的 IDE。您无法在其中打开图像。但是,如果您只想这样做,您可以点击download the image 来查看它

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • 当我尝试 download the image 时,它说文件无法在我的 Mac 上打开,因为文件已损坏或无法打开。
    • 您下载的文件对吗?应该够了
    猜你喜欢
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2016-03-03
    • 1970-01-01
    相关资源
    最近更新 更多