【问题标题】:Discord.JS getting all attachments from a messageDiscord.JS 从消息中获取所有附件
【发布时间】:2021-02-14 07:17:11
【问题描述】:

您好,我想做一个 say 命令,发送在使用命令时发送的附件,例如有人在附加 3 个附件时使用 !say,并且它在我上次尝试这样做时发送 3 个附件我只能得到第一个附件,但我想获取邮件附带的所有附件

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    如果要获取附加到消息的文件或图像,可以访问message 对象的attachments 属性。这将返回一个附件集合,您可以遍历这些附件并将其附加到您的新邮件中。

    例如

    client.on("message", message => {
        if (message.attachments) {
            let attachments = message.attachments;
            for (let file of attachments) {
                message.channel.send({files: [file]});
            }
        }
    })
    

    您可以在 Discord.js documentation 中获得更多信息。

    【讨论】:

    • 放置此代码后,当有人使用命令并附加附件时出现错误,错误为TypeError: Cannot read probably "path" of undefined
    猜你喜欢
    • 2020-10-02
    • 2019-05-19
    • 2020-11-29
    • 2021-06-26
    • 1970-01-01
    • 2017-05-02
    • 2021-06-21
    • 2021-10-17
    • 2018-09-16
    相关资源
    最近更新 更多