Bulk delete stopping at 50

Hi, i'm trying to use the bulk delete function (all messages are from today so no 14 days limit etc.) But when I tell it to bulk delete 100 messages (api max) it deletes 50 messages
const handleBulkDelete = async (
channel: TextChannel,
amountToDelete: number,
target?: GuildMember
) => {
const messagesToDelete = await channel.messages.fetch();
const filteredMessages: Message[] = [];
if (target) {
let i = 0;
messagesToDelete.filter((msg: Message) => {
if (msg.author.id === target.id && i < amountToDelete) {
filteredMessages.push(msg);
i++;
}
});
if (filteredMessages.length === 0) return 0;
} else {
filteredMessages.push(...messagesToDelete.first(amountToDelete));
}
if (filteredMessages.length === 0) return 0;
await channel.bulkDelete(filteredMessages, true);
return filteredMessages.length;
};
const handleBulkDelete = async (
channel: TextChannel,
amountToDelete: number,
target?: GuildMember
) => {
const messagesToDelete = await channel.messages.fetch();
const filteredMessages: Message[] = [];
if (target) {
let i = 0;
messagesToDelete.filter((msg: Message) => {
if (msg.author.id === target.id && i < amountToDelete) {
filteredMessages.push(msg);
i++;
}
});
if (filteredMessages.length === 0) return 0;
} else {
filteredMessages.push(...messagesToDelete.first(amountToDelete));
}
if (filteredMessages.length === 0) return 0;
await channel.bulkDelete(filteredMessages, true);
return filteredMessages.length;
};
Discord.js: 14.14.1 | NodeJS: 18.18.0 | TypeScript: 5.3.3
No description
No description
3 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
d.js docs
d.js docs9mo ago
:method: MessageManager#fetch() Fetches message(s) from a channel. (more...)
Adan_ea
Adan_eaOP9mo ago
Ah ok i see, so if i give the number as a limit, will it go towards the limit or will it stay at the 50 ? Oh that worked ! Thank you very much :] Didn't notice this change (i'll admit it stopped deleting the asked amount a long time ago. But I kept delaying)
Want results from more Discord servers?
Add your server