-
-
Save 1011025m/6c2109cdb0178082aea1db4ddab585e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import requests | |
from math import floor | |
from urllib.parse import urlencode | |
auth_token = input('Enter your authorization token: ') | |
channel_id = input('Enter the forum channel ID: ') | |
base = f'https://discord.com/api/v9/channels/{channel_id.strip()}/threads/search?' | |
params = { | |
# 'archived': False, | |
'sort_by': 'last_message_time', | |
'sort_order': 'desc', | |
'limit': 25, | |
'tag_setting': 'match_some', | |
'offset': 0 | |
} | |
s = requests.Session() | |
s.headers = { 'Authorization': auth_token.strip() } | |
thread_count = None | |
thread_ids = [] | |
while True: | |
res = s.get(base+urlencode(params)) | |
if res.status_code == 200: | |
data = res.json() | |
for thread in data['threads']: | |
if thread['id'] not in thread_ids: | |
thread_ids.append(thread['id']) | |
else: | |
print(f'Skip {thread["id"]} - seen already') | |
if thread_count == None: | |
thread_count = data['total_results'] | |
print('Total threads:', thread_count) | |
if data['has_more'] == False: | |
break | |
else: | |
params['offset'] += 25 | |
else: | |
print(f'Error {res.status_code}: {res.json()["message"]}') | |
break | |
threads_retrieved = len(thread_ids) | |
if threads_retrieved == 0: | |
print('Target channel does not have any threads.') | |
else: | |
with open(f'threads_{channel_id}_{floor(time.time())}.txt', 'w') as f: | |
f.write('\n'.join(thread_ids)) | |
f.close() | |
print(f'Threads retrieved for channel {channel_id}. Total: {threads_retrieved}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment