【问题标题】:Discord.js V13 sending message attachmentsDiscord.js V13 发送消息附件
【发布时间】:2021-10-17 18:38:47
【问题描述】:

升级到 discord.js v13 并使用 Array.from(message.attachments.values()) 代替 message.attachments.array() 从邮件中发送附件后,

message.client.channels.cache.get("123456789").send({
    files: [Array.from(message.attachments.values())],
    content: `test`
});

我从节点模块的控制台收到错误:

Desktop\Bot\node_modules\discord.js\src\structures\MessagePayload.js:223
      if (thing.path) {
                ^

TypeError: Cannot read property 'path' of undefined

错误出现的部分在这里:

const findName = thing => {
      if (typeof thing === 'string') {
        return Util.basename(thing);
      }

      if (thing.path) {
        return Util.basename(thing.path);
      }

      return 'file.jpg';
    };

我真的很困惑出了什么问题或如何解决它,有什么帮助吗?

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您正在数组内部创建一个数组,删除多余的方括号。 Array.from() 已返回 Array 的新实例。

    message.client.channels.cache.get("channel id").send({
        files: Array.from(message.attachments.values()),
        content: `test`
    });
    

    或者,您可以使用 spread operator 将可迭代对象分散到一个数组中。

    message.client.channels.cache.get("channel id").send({
        files: [...message.attachments.values()],
        content: `test`
    });
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 2021-12-25
      • 1970-01-01
      • 2021-12-24
      • 1970-01-01
      • 2021-10-29
      • 2022-01-25
      • 1970-01-01
      • 2021-11-14
      相关资源
      最近更新 更多