Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
brought back !count
Browse files
app.py
CHANGED
@@ -70,34 +70,21 @@ async def level(ctx):
|
|
70 |
|
71 |
|
72 |
@bot.command()
|
73 |
-
async def
|
74 |
-
"""
|
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
|
94 |
-
await ctx.send(f"
|
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 |
""""""
|