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:
JavaScript
x
2
1
TypeError [MESSAGE_BULK_DELETE_TYPE]: The messages must be an Array, Collection, or number.
2
Here’s the code:
JavaScript
1
13
13
1
else if (isVallidCommnad(message, "delete")){
2
if (!message.member.hasPermission('KICK_MEMBERS')) return message.channel.send("You cannot delete messages :/");
3
if(!args[0]) return message.reply(" How many messages do you want to delete (limit 99)");
4
if(parseInt(args[0]) > 99) return message.reply("You can't delete more than 99 messages at once dude!!");
5
6
message.channel.bulkDelete(parseInt(args[0]) + 1 ).then(message =>{
7
message.channel.send(`Cleared ${args[0]} messages!`).then (message =>message.delete({timeout: 300}));
8
message.react("👌")
9
}).catch((err) =>{
10
console.log(err)
11
return message.reply("An error occurred!")
12
})
13
Advertisement
Answer
JavaScript
1
6
1
const deleteCount = parseInt(args[0], 10);
2
3
if (!deleteCount || deleteCount < 1 || deleteCount > 100) return;
4
5
message.channel.bulkDelete(deleteCount + 1).catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
6
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.