Skip to content

Discord.js Bulk Delete command

I am trying to add a bulk delete command to my bot but when I type how many messages I want to delete, I get the following error:

TypeError [MESSAGE_BULK_DELETE_TYPE]: The messages must be an Array, Collection, or number.

Here’s the code:

else if (isVallidCommnad(message, "delete")){
            if (!message.member.hasPermission('KICK_MEMBERS'))  return"You cannot delete messages :/");
            if(!args[0]) return message.reply(" How many messages do you want to delete (limit 99)");
            if(parseInt(args[0]) > 99) return message.reply("You can't delete more than 99 messages at once dude!!");
  [0]) + 1 ).then(message =>{
      `Cleared ${args[0]} messages!`).then (message =>message.delete({timeout: 300}));
            }).catch((err) =>{
                return message.reply("An error occurred!")



const deleteCount = parseInt(args[0], 10);

if (!deleteCount || deleteCount < 1 || deleteCount > 100) return; + 1).catch(error => message.reply(`Couldn't delete messages because of: ${error}`));

To use the parseInt(), you have to add the decimal base, so 10 -> parseInt(args[0], 10);. The snippet of code I have put above is working well.

User contributions licensed under: CC BY-SA
1 People found this is helpful