discord.js特定通道嵌入

discord.js特定通道嵌入,discord.js,Discord.js,我想知道如何使它,如果你把一个图像在某个频道,它变成一个嵌入 我目前的代码是: const Discord=require(“Discord.js”); const{MessageEmbed}=require(“discord.js”); const{Client,RichEmbed}=require(“discord.js”); module.exports={ 名称:'图标', 运行:异步(客户端、消息、参数)=>{ 如果(message.channel.id=='7089147033380

我想知道如何使它,如果你把一个图像在某个频道,它变成一个嵌入

我目前的代码是:

const Discord=require(“Discord.js”);
const{MessageEmbed}=require(“discord.js”);
const{Client,RichEmbed}=require(“discord.js”);
module.exports={
名称:'图标',
运行:异步(客户端、消息、参数)=>{
如果(message.channel.id=='708914703338045491'){
message.delete();
让usermsg=args.slice(0.join)(“”);
const embed=new MessageEmbed()
.setColor(“2f3136”)
.setImage(usermsg);
message.delete().catch();
message.channel.send(嵌入)
}
}
}

如果您将图像上载到邮件中,它将保存到
邮件附件中,因此您可以使用此集合进行检查。Discord附件可以是一个文件,也可以是视频,所以你需要检查文件格式,简单的方法是-它的检查结束链接到它的内容的有效格式,所以我创建了2个函数

  • 第一:查找附件
  • 第二:用于验证url中的图像格式
const{MessageEmbed}=require(“discord.js”);
常量avalibleFormats=['png','gif','jpeg','jpg']
module.exports={
名称:'图标',
运行:异步(客户端、消息、参数)=>{
如果(message.channel.id!=“708914703338045491”){
返回;
}
让image=getImage(消息)
如果(!图像){
返回;
}
let embed=new MessageEmbed();
embed.setImage(image.url)
message.channel.send(嵌入)
}
}
const getImage=(message)=>message.attachments.find(attachment=>checkFormat(attachment.url))
const checkFormat=(url)=>availableformats.some(format=>url.endsWith(format))

因此您可以将其用作功能并添加到
bot.on('message
block)。您给出了此代码,因此我使用您的模板。