是否有办法拦截附加文件使用Discord.js和删除某些文件类型的消息?



我知道我可以使用JavaScript扫描文件类型,并且我知道如何删除消息。这不是问题。我只是不知道是否有可能拦截附带文件与不和谐。js。如有任何帮助,我将不胜感激。

因此,据我所知,您正在寻找删除包含特定文件类型的消息。你应该这样做:

const fileTypes = ['.jpg']; //leave the file types here
message.attachments.forEach(attachment => { //iterates over all attachments
for (fileType of fileTypes) { //iterates over all the file types provided
if (attachment.name.includes(fileType)) { //checks if the name of the attachment includes the file type
message.delete() // if yes, deletes
message.channel.send(`Message deleted because it contains a ${fileType} file`);
};
};
});