首页 > 解决方案 > 如何将文件附加到消息中?

问题描述

我希望我的机器人在使用命令时将文件转发给提到的用户,问题是我不知道该怎么做。

if (command === "file") {
    if (message.channel.id != "700038969253167125") return;
    message.delete();
    message.channel.send(`> <@${message.author.id}> ✅`)

    let filejoin = args.join(" ");
    if (!filejoin)

        client.channels.cache.get('700052786909282344').send(`:information_source: **|** Ha llegado un nuevo archivo (<@${message.author.id}>)\n\n"${filejoin}"`);
    if (message.author.bot) return;

    client.channels.cache.get('700052786909282344').send(`:information_source: **|** Ha llegado un nuevo archivo (<@${message.author.id}>)\n\n"${filejoin}"`).then(async m => {

    });

}

标签: discord.js

解决方案


.send()您可以使用该方法发送文件。

正如您在此答案的评论中所述,您希望将附加到包含命令的消息的文件发送给您。你可以这样做:

const user = client.users.cache.get("YOUR_ID")
if (message.attachments.array().length) {
   message.attachments.forEach((attachment) => user.send({ files: [ attachment ] }))
   user.send(`These files were sent by ${message.author.tag}`)
}

推荐阅读