discord.js - 如何将文件附加到消息中?
问题描述
我希望我的机器人在使用命令时将文件转发给提到的用户,问题是我不知道该怎么做。
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 => {
});
}
解决方案
.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}`)
}
推荐阅读
- typescript - TypeScript - 如何使用动态键键入接口对象
- angular - 如何在 ngx-treeview angular js 中为每个元素添加 id
- angular - MatMenu 悬停在打开的 MatMenu 下方显示 Button
- python - 如何在 Flask 中使用输入框设置变量
- svn - Tortoise SVN - 无法搁置新目录:“无法搁置一个或多个路径。”
- python - Sklearn 线性回归似乎不适合数据
- python - 在python中计算信号功率的有效方法
- javascript - 将图像 ID 映射到 Api 对象 ID
- html - 类导航栏品牌大小不变
- angular - 如何通过 Angular 11 中的管道传递 Kendo UI 网格中的数据字段?