Javascript 如何在同一邮件中发送附件和嵌入内容?

Javascript 如何在同一邮件中发送附件和嵌入内容?,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,如何在同一邮件中发送附件和嵌入内容 要发送附件,请执行以下操作: if (message.content === ';file') { const attachment = new Attachment('https://i.imgur.com/FpPLFbT.png'); message.channel.send(`text`, attachment); } 要发送嵌入,请执行以下操作: if (msg.content === ';name') { const embed = n

如何在同一邮件中发送附件和嵌入内容

要发送附件,请执行以下操作:

if (message.content === ';file') {
  const attachment = new Attachment('https://i.imgur.com/FpPLFbT.png');
  message.channel.send(`text`, attachment);
}
要发送嵌入,请执行以下操作:

if (msg.content === ';name') {
  const embed = new Discord.RichEmbed()
    .setTitle(`About`)
    .setDescription(`My name is <@${msg.author.id}>`)
    .setColor('RANDOM');
  msg.channel.send(embed);
}
if(msg.content==';name'){
const embed=new Discord.RichEmbed()
.setTitle(`About`)
.setDescription(`My name is`)
.setColor(“随机”);
msg.channel.send(嵌入);
}
该功能可以采取不同的操作

所以你可以这样做:

const Discord=require('Discord.js');
const client=new Discord.client();
client.on('message',(msg)=>{
msg.channel.send({
嵌入:新建Discord.RichEmbed()
.setTitle(“一个光滑的小嵌入物”)
.setColor(0xFF0000)
.setDescription('您好,这是一个光滑的嵌入!'),
档案:[{
附件:“./README.md”,
名称:“自述文件”
}]
})
.then(console.log)
.catch(控制台错误);
});
但是,如果要在嵌入中添加图像,只需遵循中的示例或api文档中给出的示例:

//发送包含本地图像的嵌入
channel.send('这是一个嵌入'{
嵌入:{
缩略图:{
url:'attachment://file.jpg'
}
},
档案:[{
附件:“完整的/path/to/file.jpg”,
名称:'file.jpg'
}]
})
.then(console.log)
.catch(控制台错误);

要了解如何完成任务,首先需要了解
TextBasedChannel.send()
方法的工作原理。让我们从文档中看一看。

.send([content],[options])

内容
()消息文本。
选项
(或)邮件的选项也可以是RichEmbed或附件

现在,让我们看看您的用法是如何应用的


message.channel.send(`text`,附件);
在这种情况下,
`text`
用作方法的
内容
参数,
附件
作为
选项
参数传递

msg.channel.send(嵌入);
这里,省略
content
参数,并将
embed
作为
options
参数传递


在保持相同的代码样式的同时,可以利用对象来保存
选项
参数的嵌入和附件

//const{Attachment,RichEmbed}=require('discord.js');
常量附件=新附件('https://puu.sh/DTwNj/a3f2281a71.gif“,”test.gif“);
const embed=新的RichEmbed()
.setTitle(“**测试**”)
.setImage('attachment://test.gif')//删除此行以单独显示附件。
message.channel.send({embed,files:[附件]})
.catch(控制台错误);

非常感谢您提供的信息……:)感谢你的辛勤工作……这也在起作用。。谢谢你们的努力:)@dhirajsingkarki请不要犹豫,接受这个缓慢的回答,因为它比我的回答更详细。这样,寻找答案的人就会知道解决方案是有效的