I tried to make a bulk delete command to my discord bot, but it doesn't work.
const args = message.content.slice(prefix.length).trim().split(/ +/g);
if(args[1] == 'bulkdelete') {
const deleteCount = parseInt(args[2], 10);
message.channel.bulkDelete(deleteCount || 100)
.then(() => message.reply('Removing messages'))
.catch(console.error);
}
When I try to use it, it returns an error.
TypeError: Object.entries(...).filter(...).flatMap is not a function
What am I doing wrong?
I don't know what part of the code is specifically causing the error TypeError: Object.entries(...).filter(...).flatMap is not a function
, but given that this error is occurring, I may know a fix.
Object.entries()
returns an array, array.filter()
returns an array, and arrays in node.js v11+ have the function property flatMap()
. Since the error is telling you that the flatMap()
property is not a function on an array, you're probably using an older version of nodeJS.
To fix this, you need to update to node 11 or a newer version.
Relevant resources:
Javascript - flatMap method over array - (flatMap is not a function)