Skip to content
Advertisement

Clear command is not deleting messages correctly discord.js v13

I want to make a bulk-clear command for my bot. I tried this code:

            await message.channel.messages.fetch({ limit: args[0] }).then(messages => {
                message.channel.send(`Deleting Messages...`).then(msg => {
                    setTimeout(() => msg.delete(), 500)
                })
                message.channel.bulkDelete(messages);
            });

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

  1. 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()
  2. Channel.bulkDelete() is not removing messages that are older than 2 weeks by default! To enable filterOld parameter you’ll have to use Channel.bulkDelete(number, true) and you’ll be able to delete these messages as well!
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement