lunarflu HF staff commited on
Commit
c67eb35
·
1 Parent(s): c111c5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -88,6 +88,23 @@ async def count_messages(ctx, channel_name: str):
88
  await ctx.send(f"Message count per user in #{channel_name}:\n{top_list}")
89
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
 
93
 
 
88
  await ctx.send(f"Message count per user in #{channel_name}:\n{top_list}")
89
 
90
 
91
+ @bot.command()
92
+ async def count(ctx):
93
+ """Count messages per user in a specific channel."""
94
+ channel = ctx.channel
95
+
96
+ if not channel:
97
+ await ctx.send("Channel not found.")
98
+ return
99
+
100
+ message_counts = {}
101
+ async for message in channel.history(limit=None):
102
+ #if not message.author.bot:
103
+ message_counts[message.author] = message_counts.get(message.author, 0) + 1
104
+
105
+ sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
106
+ top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users])
107
+ await ctx.send(f"Message count per user:\n{top_list}")
108
 
109
 
110