lunarflu HF staff commited on
Commit
79a1edd
·
1 Parent(s): 8010cdb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -44,6 +44,35 @@ async def save_messages(ctx, channel_id: int):
44
  discord_file = discord.File(file)
45
  await ctx.send(file=discord_file)
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  """"""
49
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
 
44
  discord_file = discord.File(file)
45
  await ctx.send(file=discord_file)
46
 
47
+
48
+ @bot.command()
49
+ async def save_forum(ctx, channel_id: int, file_name: str):
50
+ channel = bot.get_channel(channel_id)
51
+ if not channel:
52
+ await ctx.send("Channel not found.")
53
+ return
54
+
55
+ threads = {} # Dictionary to store messages by thread ID
56
+
57
+ async for message in channel.history(limit=None):
58
+ thread_id = message.reference.channel_id if message.reference else message.id
59
+ if thread_id not in threads:
60
+ threads[thread_id] = []
61
+ threads[thread_id].append(message)
62
+
63
+ with open(file_name, 'w', encoding='utf-8') as file:
64
+ for thread_id, messages in threads.items():
65
+ file.write(f"Thread ID: {thread_id}\n")
66
+ for message in messages:
67
+ file.write(f"{message.content}\n")
68
+ file.write("\n")
69
+
70
+ await ctx.send(f"Forum messages from {channel.name} saved to file")
71
+
72
+ with open(file_name, 'rb') as file:
73
+ discord_file = discord.File(file)
74
+ await ctx.send(file=discord_file)
75
+
76
 
77
  """"""
78
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)