Spaces:
Running on CPU Upgrade

lunarflu HF staff commited on
Commit
6fdc6ae
·
1 Parent(s): 3fd31a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -94,9 +94,14 @@ async def count(ctx):
94
  message_counts = {}
95
 
96
  for channel in ctx.guild.text_channels:
97
- async for message in channel.history(limit=None):
98
- message_counts[message.author] = message_counts.get(message.author, 0) + 1
99
-
 
 
 
 
 
100
  sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
101
  top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users])
102
  await ctx.send(f"Message count per user in all text channels:\n{top_list}")
 
94
  message_counts = {}
95
 
96
  for channel in ctx.guild.text_channels:
97
+ try:
98
+ async for message in channel.history(limit=None):
99
+ if not message.author.bot:
100
+ message_counts[message.author] = message_counts.get(message.author, 0) + 1
101
+ except discord.Forbidden:
102
+ # Handle the Forbidden error
103
+ await ctx.send(f"Missing access to read messages in {channel.name}")
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 in all text channels:\n{top_list}")