lunarflu HF staff commited on
Commit
8a13292
1 Parent(s): fa46345

brought back !count

Browse files
Files changed (1) hide show
  1. app.py +11 -24
app.py CHANGED
@@ -70,34 +70,21 @@ async def level(ctx):
70
 
71
 
72
  @bot.command()
73
- async def top_users(ctx, limit: int = 10):
74
- """Get the top users with the highest message counts."""
75
  message_counts = {}
76
- channel = discord.utils.get(ctx.guild.text_channels, name="general") # Replace with your channel name
77
-
78
- async for message in channel.history(limit=None):
79
- message_counts[message.author] = message_counts.get(message.author, 0) + 1
80
-
81
- sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
82
- top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users[:limit]])
83
- await ctx.send(f"Top {limit} users by message count:\n{top_list}")
84
 
 
 
 
 
 
 
 
85
 
86
-
87
- """
88
- for member in ctx.guild.members:
89
- #if not member.bot:
90
- message_counts[member] = sum(1 for _ in await ctx.history(user=member).flatten())
91
-
92
  sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
93
- top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users[:limit]])
94
- await ctx.send(f"Top {limit} users by message count:\n{top_list}")
95
- """
96
-
97
-
98
-
99
-
100
-
101
 
102
 
103
  """"""
 
70
 
71
 
72
  @bot.command()
73
+ async def count(ctx):
74
+ """Count total messages per user in all channels."""
75
  message_counts = {}
 
 
 
 
 
 
 
 
76
 
77
+ for channel in ctx.guild.text_channels:
78
+ try:
79
+ async for message in channel.history(limit=None):
80
+ message_counts[message.author] = message_counts.get(message.author, 0) + 1
81
+ except discord.Forbidden:
82
+ # Handle the Forbidden error
83
+ await ctx.send(f"Missing access to read messages in {channel.name}")
84
 
 
 
 
 
 
 
85
  sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
86
+ top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users])
87
+ await ctx.send(f"Message count per user in all text channels:\n{top_list}")
 
 
 
 
 
 
88
 
89
 
90
  """"""