Please describe the problem you are having in as much detail as possible:
I use a loop to clear more than 100 messages inside a single command call. if I specify a number greater than 100, such as 150, discord.js will return me the information that 100 messages were cleared and then 50 messages were cleared, but in fact the remaining 50 messages will not be cleared.



Include a reproducible code sample here, if possible:
// the code looks a little different, I simplified it so that it can be executed outside of my project
async function clear(msg, requestedToClear) {
if (!msg) return null
if (isNaN(requestedToClear) || requestedToClear <= 0) return msg.reply('do not joke with me')
let toClearCycleNumber = Math.ceil(requestedToClear / 100),
deletedMessagesCount = 0
if (!msg.channel.permissionsFor(msg.guild.me).has('MANAGE_MESSAGES'))
return msg.reply('give me permissions :c')
for (let i = 0; i < toClearCycleNumber; i++) {
let messagesToFetchNumber = requestedToClear - deletedMessagesCount
if (messagesToFetchNumber > 100) messagesToFetchNumber = 100
console.log('requested: ', messagesToFetchNumber)
let messages = await msg.channel.messages.fetch({ before: msg.id, limit: messagesToFetchNumber })
console.log('fetched: ', messages.size)
await msg.channel.bulkDelete(messages, true)
.then(deletedMessages => {
console.log('cleared: ', deletedMessages.size)
deletedMessagesCount += deletedMessages.size
if(deletedMessages.size < 100) console.log('total cleared: ', deletedMessagesCount)
})
.catch(e => {
i = toClearCycleNumber
console.error(e)
})
}
}
Further details:
Relevant client options:
Нихуя не понял, но очень интересно
Нихуя не понял, но очень интересно
wut?
Ban SmokyPlay pls
кто согласен что смоки ебанутый - ставим класс
okay, I found the problem. MessageManager.fetch() returns a collection of messages, but some of them are returned again after deletion, as if they were not deleted. I tried not to add them to the cache, but it didn't help. I decided that I would use the ID of the message that was the last in the collection of deleted messages as the starting point, and it worked. since the problem was not on discord.js side, I'm closing this issue.
Most helpful comment
кто согласен что смоки ебанутый - ставим класс