Skip to content Skip to sidebar Skip to footer

Automatically Purge Last 10 Images Posted In Discord (discord.js)

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 co

Solution 1:

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.

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.

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.

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.

Post a Comment for "Automatically Purge Last 10 Images Posted In Discord (discord.js)"