I continue a previous post ("DiscordJS fetching more then 100 messages") as it is written to just answer the question in the comment and not ask new question. If it's not the right place, then I'm very Sorry
[Edit 08/12/2021 - as per Comment of Zsolt; thanks !]
First, Thanks @Zsolt Meszaros for guiding me to the post related to my previous question, I understand despite the fact my question was too broad that this should help a lot.
So, I tried to copy the code posted for V12/V13.
But I get an error "cannot read property 'fetch' of undefined. [I tried to change .messages to .message just in case.. not working]
I tried to change 'options' to a boolean (true or false) in case options{} was a problem, as per doc. it awaits a boolean, but no improvement either...
I must be missing something somewhere....
Now the code is at least working and I get 2 tables (authors & messages). Now the new challenge is to get number of a specific reaction on each message. I suppose a good start would be to do a loop on list.size. Then I would need to adress the Reactions through what is named "ReactionManager" then look for my emoji and count... It is written "reactions: ReactionManager { message: [Circular *1] }, on each message, but how to get inside? I tried to find example over here and there, but didn't find (apart that finding bot reacting on instant emoji). Here i need to see the already existing ones in my "map"
My code is, at the moment, only initiating the bot with a simple slash command. But this function and the call is not under a slash command right now it's in my main.
The use, I simply wrote the small code here below to just try to test :
client.once('ready', () => {
try {
const myChan = await client.channels.fetch(CHAN_CHALLENGE_ID);
const list = await fetchMore(myChan, 120);
const table_authors = list.map((msg) => msg.author.username);
const table_messages = list.map((msg) => msg.content);
for (let i = 0; i < list.size; i++) {
// How to get things from :
// reactions: ReactionManager { message: [Circular *1] }
}
catch (err) {
console.log(err);
}
});
With the function code you wrote above :
const { GUILD_ID, TOKEN, CHAN_ID } = require('./config.json');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const cron = require('node-cron');
const {
Client,
Intents,
Collection,
} = require('discord.js');
const client = new Client({
intents: [Intents.FLAGS.GUILDS],
});
// .
// middle code lines with slash command init & cron routines not pasted, but working
// .
async function fetchMore(channel, limit = 250) {
console.log(channel);
if (!channel) {
throw new Error(`Expected channel, got ${typeof channel}.`);
}
/* if (limit <= 100) {
return channel.messages.fetch({ limit });
} */
let collection = new Collection();
let lastId = null;
let options = {};
let remaining = limit;
while (remaining > 0) {
options.limit = remaining > 100 ? 100 : remaining;
remaining = remaining > 100 ? remaining - 100 : 0;
if (lastId) {
options.before = lastId;
}
let messages = await channel.messages.fetch(options);
if (!messages.last()) {
break;
}
collection = collection.concat(messages);
lastId = messages.last().id;
}
return collection;
}
I Hope someone can have an idea... I'm still in the learning curve of all these syntaxes, but I believe a big hint/help would be needed ;)
for reference, I use: node : V16.6.1 discord.js :v13.3.1
Thank you a lot to all contributors & helpers ! Pask