Skip to content

Commit

Permalink
Added more console.log + fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Oct 24, 2020
1 parent a12996c commit 693564e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Fetch all the messages from a Discord TextChannel
* @param {module:"discord.js".Client} client
* @param {module:"discord.js".TextChannel | module:"discord.js".NewsChannel} channel
* Fetch all the messages from a Discord TextChannel.
* @param {module:"discord.js".Client} client - Your Discord.js Client.
* @param {module:"discord.js".TextChannel | module:"discord.js".NewsChannel} channel - The ID of the Discord TextChannel.
* @returns {Promise<module:"discord.js".Message[]>} - All the messages fetched.
*/
async function fetchChannelMessages(client, channel) {
Expand All @@ -26,7 +26,7 @@ async function fetchChannelMessages(client, channel) {
if (messages.size === 0) break;

lastMessageID = messages.last().id;
console.log(channel.name, total.length);
console.log(`#${channel.name} : ${total.length}`);
total.push(...messages.array());
}

Expand All @@ -35,15 +35,17 @@ async function fetchChannelMessages(client, channel) {

/**
* Fetch all the messages from a Discord Guild.
* @param {module:"discord.js".Client} client - The Discord Client.
* @param {string} guildID - A guild ID.
* @param {module:"discord.js".Client} client - Your Discord.js Client.
* @param {string} guildID - The ID of the Guild to be fetch.
* @returns {Promise<module:"discord.js".Message[]>} - All the messages fetched.
*/
async function fetchGuildMessages(client, guildID) {
const m = [];
const channels = client.guilds.cache.get(guildID).channels.cache.filter(c => c.isText());
console.log(channels);
console.log(`Getting the messages from these channels : ${channels.map(c => `#${c.name}`).sort().join('\n')}`);

for (const channel of channels.array()) {
console.log(`Getting messages from : #${channel.name}.`)
const messages = await fetchChannelMessages(client, channel);

if (!m.find(c => c.id === channel.id))
Expand All @@ -54,6 +56,7 @@ async function fetchGuildMessages(client, guildID) {
m.find(c => c.id === channel.id).messages.push(...messages.map(m => m.cleanContent));
}

console.log(`Finished fetching messages, messages count: ${m.length}`);
return m;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"engineStrict": true,
"engines": {
"node": ">=14.0.0",
"discord.js": ">=12.4.0"
"discord.js": ">=12.0.0"
},
"keywords": [
"discord.js",
Expand Down

0 comments on commit 693564e

Please sign in to comment.