Compare commits
4 Commits
f602b22c8a
...
e22705600a
| Author | SHA1 | Date | |
|---|---|---|---|
| e22705600a | |||
| 9aaad019a5 | |||
| 45190bd0ff | |||
| 458a8c4881 |
1
.env
Normal file
1
.env
Normal file
@@ -0,0 +1 @@
|
||||
MTQwNDI0NTI1MTk4Nzg2OTgyOA.G_GnSa.wsi4qZ_4F40EU19wxfRLA3UG521_r9TSxOL4Q0
|
||||
2982
discord_chat_logs/botcommands.csv
Normal file
2982
discord_chat_logs/botcommands.csv
Normal file
File diff suppressed because it is too large
Load Diff
1424
discord_chat_logs/general.csv
Normal file
1424
discord_chat_logs/general.csv
Normal file
File diff suppressed because it is too large
Load Diff
43
discord_chat_logs/memes.csv
Normal file
43
discord_chat_logs/memes.csv
Normal file
@@ -0,0 +1,43 @@
|
||||
message_id,timestamp_utc,author_id,author_name,author_nickname,content,attachment_urls,embeds
|
||||
687369591902830592,2020-03-11 18:41:21.419000+00:00,363740934103629835,notldnm,mbaldn,That's the shit we like 2 see ^^^,,
|
||||
687365681414668364,2020-03-11 18:25:49.086000+00:00,259747187829768192,owiedoodle,Owiedoodle,,https://cdn.discordapp.com/attachments/654795404206145566/687365681200627712/evoub68zihl41.png?ex=689a35ad&is=6898e42d&hm=8f2ca88aab099f993660ca4986477eea7265ddc9f4f05b3a4515b59519a08398&,
|
||||
675119424642220042,2020-02-06 23:23:33.947000+00:00,252891600336846849,b1rdie,Birdie,xDD,,
|
||||
675119361609957390,2020-02-06 23:23:18.919000+00:00,363740934103629835,notldnm,mbaldn,Where do u get this shit from 😂,,
|
||||
675109519126298624,2020-02-06 22:44:12.288000+00:00,252891600336846849,b1rdie,Birdie,You've got really ugly toes,,
|
||||
675109408413450280,2020-02-06 22:43:45.892000+00:00,337320887873175564,leum_ayesheep,lEUM,yoyoyo,,
|
||||
669635307703894017,2020-01-22 20:11:38.579000+00:00,252891600336846849,b1rdie,Birdie,and never fucking forget that,,
|
||||
669631131565555722,2020-01-22 19:55:02.910000+00:00,363740934103629835,notldnm,mbaldn,,https://cdn.discordapp.com/attachments/654795404206145566/669631131288600596/unknown.png?ex=689a4a96&is=6898f916&hm=9bfc06321abda09d52d84dfef8eabb4185d0befa4b334e8b452235494f020ef7&,
|
||||
669631019753930753,2020-01-22 19:54:36.252000+00:00,356885845094957066,unknownrelic_,B.Gilroy,send this,,
|
||||
669631003186298892,2020-01-22 19:54:32.302000+00:00,356885845094957066,unknownrelic_,B.Gilroy,https://www.amazon.co.uk/Shirt-Print-Summer-Clothes-Printed/dp/B01KVJR75A/ref=asc_df_B01KVJR75A/?tag=googshopuk-21&linkCode=df0&hvadid=344343796316&hvpos=1o4&hvnetw=g&hvrand=6580056263231779000&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=1007266&hvtargid=pla-698157171066&psc=1,,
|
||||
669630495109283870,2020-01-22 19:52:31.167000+00:00,252891600336846849,b1rdie,Birdie,and me,,
|
||||
669630317690355722,2020-01-22 19:51:48.867000+00:00,356885845094957066,unknownrelic_,B.Gilroy,https://goo.gl/maps/idX52DiCCxQY9KCC9,,"{'thumbnail': {'url': 'https://maps.google.com/maps/api/staticmap?center=54.2127942%2C-2.3937285&zoom=10&size=256x256&language=en&sensor=false&client=google-maps-frontend&signature=kUULa2KcrBX7VXD4iJi4R0OoUqM', 'proxy_url': 'https://images-ext-1.discordapp.net/external/PQSElaTdVM07cUZpzzBu75jYtloCGENdxfbENsKM1Uc/%3Fcenter%3D54.2127942%252C-2.3937285%26zoom%3D10%26size%3D256x256%26language%3Den%26sensor%3Dfalse%26client%3Dgoogle-maps-frontend%26signature%3DkUULa2KcrBX7VXD4iJi4R0OoUqM/https/maps.google.com/maps/api/staticmap', 'width': 256, 'height': 256, 'flags': 0}, 'provider': {'name': 'Google Maps'}, 'flags': 0, 'type': 'link', 'description': 'Find local businesses, view maps and get driving directions in Google Maps.', 'url': 'https://goo.gl/maps/idX52DiCCxQY9KCC9', 'title': 'Google Maps'}"
|
||||
669629433593856023,2020-01-22 19:48:18.082000+00:00,356885845094957066,unknownrelic_,B.Gilroy,beam me up,,
|
||||
669292168313176127,2020-01-21 21:28:07.773000+00:00,363740934103629835,notldnm,mbaldn,needed a bit of help with this one😂,https://cdn.discordapp.com/attachments/654795404206145566/669292167667122186/unknown.png?ex=689a6067&is=68990ee7&hm=c7850d1e6248f56ea35b7ccc6252609dbcb10604f3d2d1fe8c0cef8e5a1fd220&,
|
||||
669289253573885955,2020-01-21 21:16:32.845000+00:00,252891600336846849,b1rdie,Birdie,<@!363740934103629835> shut up ya nonce,,
|
||||
669234590480596992,2020-01-21 17:39:20.148000+00:00,363740934103629835,notldnm,mbaldn,wdum😂,,
|
||||
669234338537144340,2020-01-21 17:38:20.080000+00:00,356885845094957066,unknownrelic_,B.Gilroy,you guys good?,,
|
||||
669234007401037858,2020-01-21 17:37:01.131000+00:00,363740934103629835,notldnm,mbaldn,<@!214792217108152320> get it right he only speaks retard,,
|
||||
669231007995527178,2020-01-21 17:25:06.017000+00:00,252891600336846849,b1rdie,Birdie,im not fkn canadian,,
|
||||
669230981827395590,2020-01-21 17:24:59.778000+00:00,252891600336846849,b1rdie,Birdie,<@!214792217108152320> fuck you ya gypsy prick,,
|
||||
668739198710317057,2020-01-20 08:50:49.546000+00:00,214792217108152320,endarkened_one,endarkened_one,He doesnt understand english stick to canadian yh,,
|
||||
668597961789276162,2020-01-19 23:29:36.040000+00:00,363740934103629835,notldnm,mbaldn,Sorry is this 2 much for you?,,
|
||||
668597636508418078,2020-01-19 23:28:18.487000+00:00,252891600336846849,b1rdie,Birdie,??,,
|
||||
668597568959283241,2020-01-19 23:28:02.382000+00:00,363740934103629835,notldnm,mbaldn,Imagine buning on a sunday are we rlly gonna let a nitty run this shit,,
|
||||
668597253975310345,2020-01-19 23:26:47.284000+00:00,252891600336846849,b1rdie,Birdie,ni ce,,
|
||||
668597229023657997,2020-01-19 23:26:41.335000+00:00,363740934103629835,notldnm,mbaldn,Almost as bad as I was 😂,,
|
||||
668597196987564053,2020-01-19 23:26:33.697000+00:00,363740934103629835,notldnm,mbaldn,It's big brain time ^^,,
|
||||
668596983128129595,2020-01-19 23:25:42.709000+00:00,252891600336846849,b1rdie,Birdie,and as before i challenge thine owner @muisic <@!363740934103629835>,,
|
||||
668596903948320778,2020-01-19 23:25:23.831000+00:00,252891600336846849,b1rdie,Birdie,i am very once stoned again,,
|
||||
668230833907433483,2020-01-18 23:10:45.932000+00:00,356885845094957066,unknownrelic_,B.Gilroy,,https://cdn.discordapp.com/attachments/654795404206145566/668230833747918848/bear_for_disc.jpg?ex=689a7875&is=689926f5&hm=2a377ba36828f376fb8798dabeec5a107ae6950890e29e024a51a288d78e935b&,
|
||||
667465413084446741,2020-01-16 20:29:15.387000+00:00,356885845094957066,unknownrelic_,B.Gilroy,add,,
|
||||
667464727387045918,2020-01-16 20:26:31.904000+00:00,337320887873175564,leum_ayesheep,lEUM,<@!363740934103629835>,,
|
||||
667464707258712064,2020-01-16 20:26:27.105000+00:00,337320887873175564,leum_ayesheep,lEUM,slide us back in boiii,,
|
||||
667464368446767132,2020-01-16 20:25:06.326000+00:00,337320887873175564,leum_ayesheep,lEUM,oh no,,
|
||||
667464343419486258,2020-01-16 20:25:00.359000+00:00,356885845094957066,unknownrelic_,B.Gilroy,<@!337320887873175564>,,
|
||||
667464312155144242,2020-01-16 20:24:52.905000+00:00,356885845094957066,unknownrelic_,B.Gilroy,i made a band,,
|
||||
667464164092149760,2020-01-16 20:24:17.604000+00:00,337320887873175564,leum_ayesheep,lEUM,<@!356885845094957066>,,
|
||||
667464147851542528,2020-01-16 20:24:13.732000+00:00,337320887873175564,leum_ayesheep,lEUM,https://godinguitars.com/product/session-ltd-cherry-burst-hg-mn,,"{'thumbnail': {'url': 'https://godinguitars.com/wp-content/uploads/2019/02/47680-1024x1024.jpg', 'proxy_url': 'https://images-ext-1.discordapp.net/external/3qX7nQzisigqgN_a1G6W6WJAOIJKvgZhAK7N5e9qV-I/https/godinguitars.com/wp-content/uploads/2019/02/47680-1024x1024.jpg', 'width': 1024, 'height': 1024, 'flags': 0}, 'provider': {'name': 'Godin Guitars', 'url': 'https://godinguitars.com'}, 'author': {'name': 'Godin Admin', 'url': 'https://godinguitars.com/author/godinv3'}, 'flags': 0, 'type': 'link', 'description': 'Need a cool-looking and versatile solid-body electric? Look no further than the Godin Session LTD Series. Offering a Hum-Single-Single pickup configuration, the Session LTD Cherry Burst HG MN can hand', 'url': 'https://godinguitars.com/product/session-ltd-cherry-burst-hg-mn', 'title': 'Session LTD Cherry Burst HG MN | Godin Guitars'}"
|
||||
667463162676641837,2020-01-16 20:20:18.848000+00:00,356885845094957066,unknownrelic_,B.Gilroy,,https://cdn.discordapp.com/attachments/654795404206145566/667463162676641836/Intro.wav?ex=689a5082&is=6898ff02&hm=29d74f40d1b9813ea28f2d2feda791643004728dedce45d902dffcbbd6584aa6&,
|
||||
667463066589593610,2020-01-16 20:19:55.939000+00:00,356885845094957066,unknownrelic_,B.Gilroy,,https://cdn.discordapp.com/attachments/654795404206145566/667463065926762508/Recording_12.wav?ex=689a506b&is=6898feeb&hm=7fc16a228de77f5cfeb1987c246a0dc01bb77407ec30066988e9c215a45aa002&,
|
||||
667461253899223040,2020-01-16 20:12:43.760000+00:00,228537642583588864,Vexera,Vexera,,https://cdn.discordapp.com/attachments/654795404206145566/667461253316476956/nuke.png?ex=689a4ebb&is=6898fd3b&hm=849ed1e596ba5f9c691c340ac05100bad71810eb5790cbeb71dd1ff628867cfa&,
|
||||
667461247712755713,2020-01-16 20:12:42.285000+00:00,214792217108152320,endarkened_one,endarkened_one,+nuke MusicByA,,
|
||||
|
@@ -0,0 +1 @@
|
||||
message_id,timestamp_utc,author_id,author_name,author_nickname,content,attachment_urls,embeds
|
||||
|
22
discord_chat_logs/nsfw.csv
Normal file
22
discord_chat_logs/nsfw.csv
Normal file
@@ -0,0 +1,22 @@
|
||||
message_id,timestamp_utc,author_id,author_name,author_nickname,content,attachment_urls,embeds
|
||||
680751267647193093,2020-02-22 12:22:29.954000+00:00,363740934103629835,notldnm,mbaldn,https://tse2.mm.bing.net/th?id=OGC.a576576e973c556501266069fdc589e1&pid=Api&rurl=https%3a%2f%2fmedia.giphy.com%2fmedia%2fYVqfKhjARWVxpN43gk%2fgiphy.gif&ehk=aWFb%2bNgfK%2fFDdIzAx1Yt6ZIvnMRyFQq5VA%2bfm1nnEys%3d,,"{'thumbnail': {'url': 'https://tse2.mm.bing.net/th?id=OGC.a576576e973c556501266069fdc589e1&pid=Api&rurl=https%3a%2f%2fmedia.giphy.com%2fmedia%2fYVqfKhjARWVxpN43gk%2fgiphy.gif&ehk=aWFb%2bNgfK%2fFDdIzAx1Yt6ZIvnMRyFQq5VA%2bfm1nnEys%3d', 'proxy_url': 'https://images-ext-1.discordapp.net/external/5s54jB7lA81aRnksIthdHrP_kEv0tvFTrQUDy1vH6jo/%3Fid%3DOGC.a576576e973c556501266069fdc589e1%26pid%3DApi%26rurl%3Dhttps%253a%252f%252fmedia.giphy.com%252fmedia%252fYVqfKhjARWVxpN43gk%252fgiphy.gif%26ehk%3DaWFb%252bNgfK%252fFDdIzAx1Yt6ZIvnMRyFQq5VA%252bfm1nnEys%253d/https/tse2.mm.bing.net/th', 'width': 480, 'height': 480, 'flags': 0}, 'flags': 0, 'type': 'image', 'url': 'https://tse2.mm.bing.net/th?id=OGC.a576576e973c556501266069fdc589e1&pid=Api&rurl=https%3a%2f%2fmedia.giphy.com%2fmedia%2fYVqfKhjARWVxpN43gk%2fgiphy.gif&ehk=aWFb%2bNgfK%2fFDdIzAx1Yt6ZIvnMRyFQq5VA%2bfm1nnEys%3d'}"
|
||||
680740168055128080,2020-02-22 11:38:23.605000+00:00,214792217108152320,endarkened_one,endarkened_one,^^ spitting fax,,
|
||||
680740074425548873,2020-02-22 11:38:01.282000+00:00,252891600336846849,b1rdie,Birdie,<@!214792217108152320> definitely does though,,
|
||||
680740032117604362,2020-02-22 11:37:51.195000+00:00,252891600336846849,b1rdie,Birdie,"furthering my theory, that <@!363740934103629835> don't get any puss",,
|
||||
680739937091584032,2020-02-22 11:37:28.539000+00:00,252891600336846849,b1rdie,Birdie,therefore constantly assuming that NSFW has to be something sexual,,
|
||||
680739892980088963,2020-02-22 11:37:18.022000+00:00,252891600336846849,b1rdie,Birdie,"turn on's being ""sexual""",,
|
||||
680739870246830083,2020-02-22 11:37:12.602000+00:00,252891600336846849,b1rdie,Birdie,"I said, something unrelated to porn, and you said you don't know what turns me on",,
|
||||
680720300480135359,2020-02-22 10:19:26.806000+00:00,363740934103629835,notldnm,mbaldn,that made literally no sense 😂,,
|
||||
680712476232384532,2020-02-22 09:48:21.360000+00:00,252891600336846849,b1rdie,Birdie,virginz,,
|
||||
680712462668136449,2020-02-22 09:48:18.126000+00:00,252891600336846849,b1rdie,Birdie,see what i mean?,,
|
||||
680712445659971618,2020-02-22 09:48:14.071000+00:00,252891600336846849,b1rdie,Birdie,nsfw doesn't need to be fucking porn dude,,
|
||||
680712408498831405,2020-02-22 09:48:05.211000+00:00,252891600336846849,b1rdie,Birdie,bruh,,
|
||||
680712079245967380,2020-02-22 09:46:46.711000+00:00,363740934103629835,notldnm,mbaldn,well shit idk what turns u on but that aint it,,
|
||||
680711695920005121,2020-02-22 09:45:15.319000+00:00,252891600336846849,b1rdie,Birdie,any discord server that has an NSFW channel that isn't used for posting gore memes is just filled with incompetent virgins,,
|
||||
667397528915935232,2020-01-16 15:59:30.540000+00:00,252891600336846849,b1rdie,Birdie,You're welcome,,
|
||||
654066510427455504,2019-12-10 21:06:48.054000+00:00,235088799074484224,Rythm,Rythm,"**Thank you for adding me!** ✅
|
||||
`-` My prefix here is `!`
|
||||
`-` You can see a list of commands by typing `!help`
|
||||
`-` You can change my prefix with `!settings prefix`
|
||||
`-` If you need help, feel free to join our support server at **<https://rythmbot.co/support>**
|
||||
**By having Rythm in your server and using Rythm, you agree to the following Terms of Service: <https://rythmbot.co/tos>**",,
|
||||
|
1
discord_chat_logs/oop.csv
Normal file
1
discord_chat_logs/oop.csv
Normal file
@@ -0,0 +1 @@
|
||||
message_id,timestamp_utc,author_id,author_name,author_nickname,content,attachment_urls,embeds
|
||||
|
1540
discord_chat_logs/original_dons.csv
Normal file
1540
discord_chat_logs/original_dons.csv
Normal file
File diff suppressed because it is too large
Load Diff
1286
discord_chat_logs/pmmp_gang_exclusive.csv
Normal file
1286
discord_chat_logs/pmmp_gang_exclusive.csv
Normal file
File diff suppressed because it is too large
Load Diff
7
discord_chat_logs/read_this_shit_first.csv
Normal file
7
discord_chat_logs/read_this_shit_first.csv
Normal file
@@ -0,0 +1,7 @@
|
||||
message_id,timestamp_utc,author_id,author_name,author_nickname,content,attachment_urls,embeds
|
||||
667469468242542602,2020-01-16 20:45:22.212000+00:00,363740934103629835,notldnm,mbaldn,type '+getrole ur new' to join the server,,
|
||||
667469408058474536,2020-01-16 20:45:07.863000+00:00,363740934103629835,notldnm,mbaldn,+ fuck you u think i have rules?,,
|
||||
667469373296082944,2020-01-16 20:44:59.575000+00:00,363740934103629835,notldnm,mbaldn,+ don't be offened by anthing that is said we're all in it for the jokes,,
|
||||
667469160305131530,2020-01-16 20:44:08.794000+00:00,363740934103629835,notldnm,mbaldn,Rules:,,
|
||||
667469071763243039,2020-01-16 20:43:47.684000+00:00,363740934103629835,notldnm,mbaldn,𝓦𝓮 𝓭𝓸𝓷𝓽 𝓭𝓸 𝓟𝓸𝓵𝓲𝓽𝓲𝓬𝓪𝓵 𝓒𝓸𝓻𝓻𝓮𝓬𝓽𝓷𝓮𝓼𝓼,,
|
||||
667469050888192021,2020-01-16 20:43:42.707000+00:00,363740934103629835,notldnm,mbaldn,Fuck you, Welcome to The Cult,,
|
||||
|
@@ -1,9 +1,7 @@
|
||||
# discord_export_bot.py
|
||||
# discord_export_bot_v2.py
|
||||
# This bot connects to a Discord server and exports the entire message
|
||||
# history from every accessible text channel into separate CSV files.
|
||||
|
||||
# Make sure to install the discord.py library first:
|
||||
# pip install discord.py
|
||||
# This version uses a more robust task-based approach to prevent hanging.
|
||||
|
||||
import discord
|
||||
import csv
|
||||
@@ -11,47 +9,34 @@ import os
|
||||
import asyncio
|
||||
|
||||
# --- Configuration ---
|
||||
# Place your Bot Token here. Treat this like a password!
|
||||
# It's recommended to use environment variables for security.
|
||||
BOT_TOKEN = "YOUR_BOT_TOKEN_HERE"
|
||||
|
||||
# The directory where the CSV files will be saved.
|
||||
# The script will create this directory if it doesn't exist.
|
||||
BOT_TOKEN = "___"
|
||||
OUTPUT_DIRECTORY = "discord_chat_logs"
|
||||
# Optional: If you want to lock the bot to one server
|
||||
# ALLOWED_SERVER_ID = 123456789012345678
|
||||
# -------------------
|
||||
|
||||
|
||||
# --- Bot Setup ---
|
||||
# Define the necessary "Intents" for the bot. Intents tell Discord what
|
||||
# events your bot needs to receive. To read messages, we need the
|
||||
# `messages` and `message_content` intents. You MUST enable these
|
||||
# in the Discord Developer Portal for your bot.
|
||||
# The intents MUST be enabled in the Discord Developer Portal.
|
||||
intents = discord.Intents.default()
|
||||
intents.guilds = True
|
||||
intents.messages = True
|
||||
intents.message_content = True # This is a privileged intent!
|
||||
intents.message_content = True # This is the most important one!
|
||||
|
||||
# Create the bot client instance with the specified intents.
|
||||
client = discord.Client(intents=intents)
|
||||
|
||||
# --- Main Export Logic ---
|
||||
async def export_channel_history(channel):
|
||||
"""
|
||||
Asynchronously fetches all messages from a given text channel
|
||||
and saves them to a CSV file.
|
||||
"""
|
||||
print(f"Starting export for channel: #{channel.name} (ID: {channel.id})")
|
||||
print(f"-> Starting export for channel: #{channel.name}")
|
||||
|
||||
# Sanitize channel name to create a valid filename
|
||||
# Replaces invalid file name characters with an underscore
|
||||
sanitized_channel_name = "".join(c if c.isalnum() else '_' for c in channel.name)
|
||||
file_path = os.path.join(OUTPUT_DIRECTORY, f"{sanitized_channel_name}.csv")
|
||||
|
||||
try:
|
||||
message_count = 0
|
||||
with open(file_path, 'w', newline='', encoding='utf-8') as csvfile:
|
||||
# Define the headers for the CSV file. This includes all the
|
||||
# useful information we can easily get from a message object.
|
||||
header = [
|
||||
'message_id', 'timestamp_utc', 'author_id', 'author_name',
|
||||
'author_nickname', 'content', 'attachment_urls', 'embeds'
|
||||
@@ -59,95 +44,98 @@ async def export_channel_history(channel):
|
||||
writer = csv.DictWriter(csvfile, fieldnames=header)
|
||||
writer.writeheader()
|
||||
|
||||
# Fetch the channel's history. `limit=None` tells the library to
|
||||
# fetch all messages. This can take a very long time and consume
|
||||
# significant memory for channels with a large history.
|
||||
# This is the part that fails without the Message Content Intent
|
||||
async for message in channel.history(limit=None):
|
||||
message_count += 1
|
||||
if message_count % 100 == 0:
|
||||
if message_count % 250 == 0: # Log progress less frequently
|
||||
print(f" ... processed {message_count} messages in #{channel.name}")
|
||||
|
||||
# Extract attachment URLs
|
||||
attachment_urls = ", ".join([att.url for att in message.attachments])
|
||||
|
||||
# Serialize embed objects to a string representation (e.g., JSON)
|
||||
# This gives a detailed look into rich embeds.
|
||||
embeds_str = ", ".join([str(embed.to_dict()) for embed in message.embeds])
|
||||
|
||||
# Write the message data as a row in the CSV
|
||||
# Handle nickname - only Member objects have nick attribute, not User objects
|
||||
author_nickname = getattr(message.author, 'nick', None) or message.author.display_name
|
||||
|
||||
writer.writerow({
|
||||
'message_id': message.id,
|
||||
'timestamp_utc': message.created_at,
|
||||
'author_id': message.author.id,
|
||||
'author_name': message.author.name,
|
||||
'author_nickname': message.author.nick,
|
||||
'author_nickname': author_nickname,
|
||||
'content': message.content,
|
||||
'attachment_urls': attachment_urls,
|
||||
'embeds': embeds_str
|
||||
})
|
||||
|
||||
if message_count > 0:
|
||||
print(f"✅ Finished exporting {message_count} messages from #{channel.name}.")
|
||||
else:
|
||||
print(f"⚠️ Channel #{channel.name} is empty or unreadable. 0 messages exported.")
|
||||
return True
|
||||
|
||||
except discord.errors.Forbidden:
|
||||
print(f"❌ ERROR: Permission denied for channel #{channel.name}. Skipping.")
|
||||
print(f"❌ ERROR: Permission denied for channel #{channel.name}. Check bot permissions. Skipping.")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ An unexpected error occurred for channel #{channel.name}: {e}")
|
||||
return False
|
||||
|
||||
# --- Bot Events ---
|
||||
@client.event
|
||||
async def on_ready():
|
||||
async def main_export_task():
|
||||
"""
|
||||
This event is triggered once the bot has successfully connected to Discord.
|
||||
The main logic for the bot's export process.
|
||||
This is run as a background task to avoid blocking.
|
||||
"""
|
||||
print(f'Logged in as: {client.user.name} (ID: {client.user.id})')
|
||||
# Wait until the bot is fully ready before starting
|
||||
await client.wait_until_ready()
|
||||
|
||||
print('------')
|
||||
print("Bot is ready. Starting export process...")
|
||||
|
||||
# Create the output directory if it doesn't exist
|
||||
if not os.path.exists(OUTPUT_DIRECTORY):
|
||||
os.makedirs(OUTPUT_DIRECTORY)
|
||||
print(f"Created output directory: {OUTPUT_DIRECTORY}")
|
||||
|
||||
# Get the server (guild) the bot is in. This script assumes the bot
|
||||
# is only in ONE server. If it's in multiple, you may need to specify
|
||||
# which one to target.
|
||||
guild = client.guilds[0]
|
||||
if not guild:
|
||||
# Use the first guild the bot is in. For specific server, use client.get_guild(ALLOWED_SERVER_ID)
|
||||
if not client.guilds:
|
||||
print("Error: Bot does not appear to be in any server.")
|
||||
await client.close()
|
||||
return
|
||||
|
||||
guild = client.guilds[0]
|
||||
print(f"Targeting server: {guild.name} (ID: {guild.id})")
|
||||
|
||||
# Get a list of all text channels the bot can see
|
||||
text_channels = [channel for channel in guild.text_channels]
|
||||
print(f"Found {len(text_channels)} text channels to export.")
|
||||
|
||||
# Loop through each channel and run the export function
|
||||
for channel in text_channels:
|
||||
await export_channel_history(channel)
|
||||
# A small delay to be respectful to Discord's API, although
|
||||
# the library handles rate limiting automatically.
|
||||
await asyncio.sleep(1)
|
||||
|
||||
print('------')
|
||||
print("All channels have been processed. The bot will now shut down.")
|
||||
|
||||
# Shuts down the bot once the export is complete.
|
||||
# This properly closes the bot's connection.
|
||||
await client.close()
|
||||
|
||||
@client.event
|
||||
async def on_ready():
|
||||
"""
|
||||
This event is triggered once the bot has successfully connected.
|
||||
It now only prints a ready message and starts the main task.
|
||||
"""
|
||||
print(f'Logged in as: {client.user.name} (ID: {client.user.id})')
|
||||
# Schedule the main task to run in the background
|
||||
client.loop.create_task(main_export_task())
|
||||
|
||||
# --- Run the Bot ---
|
||||
if __name__ == "__main__":
|
||||
if BOT_TOKEN == "YOUR_BOT_TOKEN_HERE":
|
||||
print("!!! ERROR: Please replace 'YOUR_BOT_TOKEN_HERE' with your actual bot token in the script.")
|
||||
else:
|
||||
try:
|
||||
# This starts the bot. The `on_ready` event will be called once it's connected.
|
||||
client.run(BOT_TOKEN)
|
||||
except discord.errors.LoginFailure:
|
||||
print("!!! ERROR: Login failed. The token is likely invalid or incorrect.")
|
||||
except Exception as e:
|
||||
print(f"!!! An error occurred while running the bot: {e}")
|
||||
|
||||
Reference in New Issue
Block a user