Spaces:
Running on CPU Upgrade

lunarflu HF staff commited on
Commit
a2fddd1
·
1 Parent(s): 3d250f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
app.py CHANGED
@@ -70,30 +70,22 @@ 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
  if not message.author.bot:
80
  message_counts[message.author] = message_counts.get(message.author, 0) + 1
81
 
82
  sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
83
- top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users[:limit]])
84
- await ctx.send(f"Top {limit} users by message count:\n{top_list}")
85
-
86
-
87
-
88
- """
89
- for member in ctx.guild.members:
90
- #if not member.bot:
91
- message_counts[member] = sum(1 for _ in await ctx.history(user=member).flatten())
92
-
93
- sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
94
- top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users[:limit]])
95
- await ctx.send(f"Top {limit} users by message count:\n{top_list}")
96
- """
97
 
98
 
99
 
 
70
 
71
 
72
  @bot.command()
73
+ async def count_messages(ctx, channel_name: str):
74
+ """Count messages per user in a specific channel."""
75
+ channel = discord.utils.get(ctx.guild.text_channels, name=channel_name)
76
+
77
+ if not channel:
78
+ await ctx.send("Channel not found.")
79
+ return
80
 
81
+ message_counts = {}
82
  async for message in channel.history(limit=None):
83
  if not message.author.bot:
84
  message_counts[message.author] = message_counts.get(message.author, 0) + 1
85
 
86
  sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
87
+ top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users])
88
+ await ctx.send(f"Message count per user in #{channel_name}:\n{top_list}")
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
 
91