├── README.md
└── discord_scrape.py
/README.md:
--------------------------------------------------------------------------------
1 | # Discord-Data-Scraping
2 | Basic examples on how to scrape data, such as member counts and messages from any discord server.
3 |
4 | ## How to get your authorization key
5 | To scrape data, an access key is required. Anyone with a discord account has a unique key.
6 | To find out your authorization key, follow this simple 4-step tutorial:
7 |
8 | 1) open and log into your discord account on your web browser
9 | 2) activate developer tools on your web browser and navigate to "Network" tab
10 |
11 | 3) while making sure the network activity is recorded, open up any random discord channel
12 |
13 | 4) navigate to "messages?limit=50" which is an api call request. Under the tab "Request Headers" the authorization key is listed as "authorization"
14 |
15 |
16 | ## How to get a server_id or channel_id
17 | The easiest way is by activating "Developer Mode" in your advanced discord settings. Once activated a simple right click and "copy ID" will copy any id needed straight to your clipboard.
18 |
19 |
20 |
--------------------------------------------------------------------------------
/discord_scrape.py:
--------------------------------------------------------------------------------
1 | """
2 | Created on Mon Sep 20 11:01:50 2021
3 | @author: Lorenz234
4 | """
5 | # Examples for scraping data from discord servers (a.k.a. guilds)
6 | # (see README.md on how to find out the server_id and channel_id)
7 |
8 | # import libraries to make get request
9 | import requests
10 | import json
11 |
12 | # your API Key goes here (see README.md on how to find out your own api key)
13 | h = {'authorization': ''} #ENTER KEY HERE
14 |
15 | # approximate_member_count (count of server members)
16 | def get_approximate_member_count(server_id):
17 | r = requests.get('https://discord.com/api/guilds/' + str(server_id) + '/preview', headers=h)
18 | j = json.loads(r.text)
19 | return j['approximate_member_count']
20 |
21 | # approximate_presence_count (count of currently online server members)
22 | def get_approximate_presence_count(server_id):
23 | r = requests.get('https://discord.com/api/guilds/' + str(server_id) + '/preview', headers=h)
24 | j = json.loads(r.text)
25 | return j['approximate_presence_count']
26 |
27 | # get the text content of the last 10 messages postet to a specific channel/direct message
28 | def get_last_10_messages_from_channel(channel_id):
29 | r = requests.get('https://discord.com/api/v9/channels/' + channel_id + '/messages?limit=10', headers=h)
30 | j = json.loads(r.text)
31 | m = [c['content'] for c in j]
32 | return m
33 |
--------------------------------------------------------------------------------