自动清除Discord(discord.js)中发布的最后10张图像 [英] Automatically purge last 10 images posted in Discord (discord.js)
问题描述
我正试图为我的机器人创建一个不和谐的系统,该系统将清除发布的最后10张图片和在聊天中上传(链接和上传),有人知道我该如何编码吗?这是我的主意(
I'm trying to create a system for my bot in discord that'll purge the last 10 images posted & uploaded (links & uploads) in the chat, does anyone know how I can go about coding this? This was my idea (sort of)
if (message.channel.type == 'general') {
if (*the last 10 messages that have been sent are images*) {
message.delete(); // delete last 10 images
}
}
推荐答案
您可以使用 fetchMessages
方法来检索承诺,它由
You can use the fetchMessages
method to retrieve a promise that consists of a collection of the the last 10 messages, by setting the limit
to 10 using the ChannelLogsQueryOptions.
使用此消息集合,就像@Chris Satchell在评论中提到的那样,您可以循环浏览并检查是否 message.attatchments
存在于所有消息中。或者,您可以检查整个邮件集合的附件
的< Collection> .size
是否等于10,如果可以,则可以继续下一步。
Using this collection of messages, as @Chris Satchell mentioned in the comments you loop through it and check if message.attatchments
is present for all of messages. Alternatively you can check if the <Collection>.size
of the attachments
for the entire collection of messages is equivalent to 10, and if it does you can go ahead with the next step.
现在,您已经拥有要删除的邮件集合,只需将此集合传递到方法 bulkDelete
。
Now that you have a collection of messages that you would like to delete, simply pass this collection into the messages
parameter of the method bulkDelete
.
因此,您获取了最后一个 TextChannel 中的10条消息,然后检查<$获取的邮件集合的c $ c> attachments 属性,然后在此集合上调用 bulkDelete
方法。
So as a result, you fetch the last 10 messages in a TextChannel, and then check the attachments
property of the fetched collection of messages and then call the bulkDelete
method on this collection.
这篇关于自动清除Discord(discord.js)中发布的最后10张图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!