lunarflu HF staff commited on
Commit
5cb8bba
1 Parent(s): d87bd06

count_messages

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import threading
4
  from discord.ext import commands
5
  import json
 
6
 
7
  import gradio_client
8
  import gradio as gr
@@ -97,6 +98,29 @@ async def count(ctx):
97
  #await ctx.send(f"Message count per user in all text channels:\n{top_list}")
98
  print(f"Message count per user in all text channels:\n{top_list}")
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  """"""
102
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
 
3
  import threading
4
  from discord.ext import commands
5
  import json
6
+ import datetime
7
 
8
  import gradio_client
9
  import gradio as gr
 
98
  #await ctx.send(f"Message count per user in all text channels:\n{top_list}")
99
  print(f"Message count per user in all text channels:\n{top_list}")
100
 
101
+
102
+ @bot.command()
103
+ async def count_messages(ctx):
104
+ if ctx.author.id == 811235357663297546:
105
+ # Calculate the start and end dates for the desired time frame
106
+ end_date = datetime.datetime.utcnow() # Current date and time
107
+ start_date = end_date - datetime.timedelta(days=1)
108
+
109
+ # Counter for messages within the time frame
110
+ message_count = 0
111
+
112
+
113
+ for channel in ctx.guild.text_channels:
114
+ try:
115
+ async for message in channel.history(limit=None, after=start_date, before=end_date):
116
+ message_count += 1
117
+
118
+
119
+ except discord.Forbidden:
120
+ print(f"Missing access to read messages in {channel.name}")
121
+
122
+ await ctx.send(f'Total messages between {start_date} and {end_date}: {message_count}')
123
+
124
 
125
  """"""
126
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)