0
votes

About 2 years ago I wrote a simple Discord bot for my server, which served some very simple tasks. Some of these tasks are API user data retrieval and the other basic message manipulation.

EDIT: I don't want to come off lazy, and so I did in fact spend about an hour searching google and here, with nothing!

Just last week my bot suddenly quit working, after hours of research, pulling my hair out, stuck on v11 with a msg.member collection that mysteriously went POOF, I finally learned about v12. I updated my npm and updated my code as Discord documentation documents. Simple, up until very very basic functions.

I am currently pulling the hair out of my head trying to use their very 'simple' bulkDelete, which always worked without a problem, well, not anymore.

Here is my original code:

msg.channel.messages.fetch({ limit: parseInt(count)}).then(
    messages => msg.channel.bulkDelete(messages)
);

What's it do? sheesh, I have no idea! it makes node.js spit an exception from the internal Discord.js classes, which I don't have enough knowledge or any on.

Here's the mumbo:

Unhandled

0|index | TypeError: Object.entries(...).filter(...).flatMap is not a function 0|index | at new APIRequest (/root/Discord/node_modules/discord.js/src/rest/APIRequest.js:24:10) 0|index | at RESTManager.request (/root/Discord/node_modules/discord.js/src/rest/RESTManager.js:39:24) 0|index | at Proxy.options (/root/Discord/node_modules/discord.js/src/rest/APIRouter.js:30:19) 0|index | at MessageManager._fetchMany (/root/Discord/node_modules/discord.js/src/managers/MessageManager.js:140:75) 0|index | at MessageManager.fetch (/root/Discord/node_modules/discord.js/src/managers/MessageManager.js:68:86) 0|index | at processServerCMD (eval at (/root/Discord/index.js:10:1), :52:25) 0|index | at Client.client.on.msg (/root/Discord/index.js:65:13) 0|index | at Client.emit (events.js:198:13) 0|index | at MessageCreateAction.handle (/root/Discord/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)

I have also tried simply doing this very simple statement

msg.channel.bulkDelete(3 /*hardwritten integer for hair-loss purposes*/);

source: https://discordjs.guide/creating-your-bot/commands-with-user-input.html#caveats-2

Same response.

What is this crap about TypeError: ....flatMap is not a function?
Am I doing something wrong?

msg.channel.messages is indeed a valid collection, however calling bulkDelete or fetch will result in the above exception, each and every single time.

Before I pull the last few follicles from my head, can somebody slap me in the face and either let me know I'm an idiot or Discord v12 is completely broken and I just wasted 4-1/2 hours on a single statement... WAT

I'm a C/C++ guy. I really have no idea what I'm doing here.

1

1 Answers

0
votes

Problem SOLVED! I had to do some more research into Array.prototype.flatMaps and it turns out that flatMaps is exclusive to Node v11 and up. I was still on Node 10, thus causing the above exception.

I hope this can help somebody else down the road, because it was quite the headache!

Update your Nodejs to v12.x