-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_counter.py
53 lines (33 loc) · 1.07 KB
/
message_counter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import discord
from dotenv import load_dotenv
from discord.utils import get
from discord.ext import commands
import random
# get tokens as environment variables (for security)
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
# initiate client
intents = discord.Intents.all()
client = discord.Client(intents = intents)
@client.event
async def on_ready():
# set status (currently broken)
# print when ready
print(f'{client.user} has connected to Discord!')
d = {}
msg = []
for channel in client.guilds[0].text_channels:
print(channel.name)
# create list of all messages in channel history
async for x in channel.history(limit=10000000000000000):
msg.append(x)
for m in msg:
if m.author.display_name in d:
d[m.author.display_name]+=1
else:
d[m.author.display_name]=1
d = {k: v for k, v in sorted(d.items(), key=lambda item: item[1], reverse=True)}
for k,v in d.items():
print(k, v)
client.run(TOKEN)