I want to make a bulk-clear command for my bot. I tried this code:
JavaScript
x
7
1
await message.channel.messages.fetch({ limit: args[0] }).then(messages => {
2
message.channel.send(`Deleting Messages...`).then(msg => {
3
setTimeout(() => msg.delete(), 500)
4
})
5
message.channel.bulkDelete(messages);
6
});
7
But it doesn’t work correctly. when I run !clear 3
, It deletes 2 messages.
- Notes: I am using discord.js v13 and node.js v16
Advertisement
Answer
- Your bot also counts your command as a message, and removes it. That’s why it only removes 2 other messages. To prevent that you will have to add a filter or remove your command first using
message.delete()
Channel.bulkDelete()
is not removing messages that are older than 2 weeks by default! To enablefilterOld
parameter you’ll have to useChannel.bulkDelete(number, true)
and you’ll be able to delete these messages as well!