lunarflu HF staff commited on
Commit
3b06990
1 Parent(s): 76423e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -48,30 +48,30 @@ async def save_messages(ctx, channel_id: int):
48
  @bot.command()
49
  async def save_forum(ctx, channel_id: int):
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("gradio-questions.json", '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("gradio-questions.json", 'rb') as file:
73
- discord_file = discord.File(file)
74
- await ctx.send(file=discord_file)
 
 
 
75
 
76
 
77
  """"""
 
48
  @bot.command()
49
  async def save_forum(ctx, channel_id: int):
50
  channel = bot.get_channel(channel_id)
51
+ threads = channel.threads
52
+
53
+
54
+
55
+ messages_data = []
56
+ async for message in thread.history(limit=None): # limit=None retrieves all messages
57
+ message_data = {
58
+ "content": message.content,
59
+ "author": message.author.name,
60
+ "timestamp": message.created_at.isoformat()
61
+ }
62
+ messages_data.append(message_data)
63
+
64
 
 
65
 
 
 
 
 
 
66
 
 
 
 
 
 
 
67
 
 
68
 
69
+
70
+
71
+
72
+
73
+
74
+
75
 
76
 
77
  """"""