Discord.js-删除没有图像的消息 [英] Discord.js - Delete messages without image
问题描述
Discord.js中是否可以删除不包含图像的频道的所有消息?我尝试了很多事情,但没有结果.我也不是Discord.js专业人员.
Is there a way in Discord.js to delete all messages of a channel that didn't contain an image? I have tried a lot of things but have come to no result. I am also not a Discord.js professional.
我将不胜感激.最好的问候
I'd appreciate some help. Best regards
推荐答案
默认情况下,Discord无法确定附件的类型,所以一种方法可以检查文件类型的结尾.您需要在允许的文件类型中添加或,并在message.attachments === 0或文件名不是您允许的图像格式的情况下删除.以下代码允许包含jpg,png,gif的消息,并添加其他您需要处理的内容.
By default Discord cant determine the type of attachment, so is 1 way check ends of file type. You need to add or
to allowed filetypes, and delete if message.attachments === 0, or filename ends not your allowed image format.
The follow code allow message with jpg,png,gif , add other whats you need to handle.
bot.on('message', message => {
if(message.attachments.size > 0) {
let findImage = message.attachments.find(attachment => attachment.filename.endsWith('png') || attachment.filename.endsWith('jpg') || attachment.filename.endsWith('gif'))
if (findImage === null) {
message.delete();
.catch(console.error)
}
} else {
message.delete();
.catch(console.error)
}})
这篇关于Discord.js-删除没有图像的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!