Best way to find and delete user messages

Hello there. So, as the title implies, I want to know what the best way to fetch ALL user messages and then delete them. My idea on how to go about this is to utilize the MessageManager.fetch({}) command to get all messages, filter them using messages.filter(m => m.author.id === USER_ID), and then using the TextChannel.bulkDelete() function and passing all the messages as an array. Before putting this into practice though, I do have some questions. First and foremost is if this method is the most efficient. I don't want to waste resources and API calls when I don't need to, so is there a better way of going about this, or is this ultimately the best way? Also, will this method guarantee that I'll fetch ALL user messages, regardless of time passed, or will the filter only get the most recent ones? The command is responsible for deleting ALL user messages (well, I'll modify it to delete a specific number of messages in the future), so getting every message the user has sent (even if the first message was 2 years ago) is essential. That is all. If someone could help me with my issue, that would be amazing. Thank you for your time and help, it is truly appreciated.
7 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Parogo_72
Parogo_722y ago
you just dont do it thats api spammy
Batimius
Batimius2y ago
Well, in the case that I do want to do it, is this the best way? Also, will the MessageManager.fetch() return me all messages, or just whatever message is cached?
Parogo_72
Parogo_722y ago
it will return 100 messages thats why you dont do it you cant fetch all messages from a channel
Batimius
Batimius2y ago
I see. Well, that's unfortunate. I intended to make a purge command similar to Dyno's, but I guess until Discord adds some type of message searching API (like how we can do Ctrl + F and filter through messages), there isn't much I can do. Thank you for your help regardless, it is truly appreciated.
Parogo_72
Parogo_722y ago
But thats for all channels True, thought they wanted for only one channel but they didnt actually mention anything about it
Suspense
Suspense2y ago
bulkDelete also can’t delete messages older than 2 weeks anyway