Skip to content

Instantly share code, notes, and snippets.

@cchudant
Created May 13, 2018 22:30
Show Gist options
  • Save cchudant/5131dfb4a3f985e72c9cb56c86824b12 to your computer and use it in GitHub Desktop.
Save cchudant/5131dfb4a3f985e72c9cb56c86824b12 to your computer and use it in GitHub Desktop.
import { blue, green } from 'chalk'
import { Client } from 'discord.js'
const client = new Client()
client.login(process.env.DISCORD_TOKEN).then(async () => {
const guild = client.guilds.get('394954745612399274')
await guild.fetchMembers()
const allResults = await Promise.all(
guild.members
.array()
.map(author =>
guild
.search({ author })
.then(({ totalResults }) => [author, totalResults])
)
)
allResults.sort(([, c1], [, c2]) => c2 - c1)
const totalMessageCount = allResults.reduce((acc, [, c]) => acc + c, 0)
console.log(`Total message count: ${totalMessageCount}`)
const pad = i => i.toString().padStart(3, '0')
allResults
.map(([author, messageCount]) => [
author.displayName,
`@${author.user.username}#${author.user.discriminator}`,
messageCount,
(messageCount / totalMessageCount * 100).toFixed(3)
])
.forEach(([displayName, mention, messageCount, ratio], i) =>
console.log(
`#${pad(i + 1)} - ${displayName} <${mention}>: ${messageCount} (${ratio}%)`
)
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment