Reputation: 1
I'm making a clear command in discord.js AND I DO KNOW THERE IS ANOTHER DUPLICATE but for some reason that DUPLICATE question doesn't solve my answer
else if(command == "clear")
{
async function clear(){
let fetched;
do {
fetched = await message.channel.messages.fetch({limit: 100});
message.channel.bulkDelete(fetched);
message.delete()
}
while(fetched.size >= 2)
}
clear();
}
and the title is the error I got
Upvotes: 0
Views: 1780
Reputation: 635
To delete messages no need to fetch them. You can just write
message.channel.bulkDelete(100,true).then(msg=>{
console.log(`${msg.size} is deleted!`)
}).catch(err=>{
console.log(err)
})
The second parameter is to filter the 2 weeks old messages. More can be found here
Upvotes: 2