lunarflu HF staff commited on
Commit
b17c838
1 Parent(s): d92c2cd

testing cache population on_ready for all channels (100 messages)

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -44,6 +44,7 @@ async def on_message(message):
44
  cakiki = bot.get_user(416019758492680203)
45
 
46
  """Backup"""
 
47
  number_of_messages = number_of_messages + 1
48
  message_link = f"[#{message.channel.name}]({message.jump_url})"
49
  msgcnt = message.content
@@ -441,6 +442,16 @@ async def on_ready():
441
  bot.log_channel = bot.get_channel(1036960509586587689) # admin-logs
442
  await asyncio.sleep(5)
443
  print(bot.log_channel)
 
 
 
 
 
 
 
 
 
 
444
 
445
 
446
  def run_bot():
 
44
  cakiki = bot.get_user(416019758492680203)
45
 
46
  """Backup"""
47
+
48
  number_of_messages = number_of_messages + 1
49
  message_link = f"[#{message.channel.name}]({message.jump_url})"
50
  msgcnt = message.content
 
442
  bot.log_channel = bot.get_channel(1036960509586587689) # admin-logs
443
  await asyncio.sleep(5)
444
  print(bot.log_channel)
445
+ guild = bot.get_guild(879548962464493619)
446
+ for channel in guild.text_channels: # helps with more accurate logging across restarts
447
+ try:
448
+ # Fetch and cache the most recent 100 messages from the channel
449
+ async for message in channel.history(limit=100):
450
+ pass
451
+ print(f"Finished caching messages for channel: {channel.name}")
452
+ except Exception as e:
453
+ print(f"An error occurred while fetching messages from {channel.name}: {e}")
454
+ await asyncio.sleep(1)
455
 
456
 
457
  def run_bot():