-
Notifications
You must be signed in to change notification settings - Fork 3
/
discord_scrape.py
32 lines (27 loc) · 1.26 KB
/
discord_scrape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Created on Mon Sep 20 11:01:50 2021
@author: Lorenz234
"""
# Examples for scraping data from discord servers (a.k.a. guilds)
# (see README.md on how to find out the server_id and channel_id)
# import libraries to make get request
import requests
import json
# your API Key goes here (see README.md on how to find out your own api key)
h = {'authorization': ''} #ENTER KEY HERE
# approximate_member_count (count of server members)
def get_approximate_member_count(server_id):
r = requests.get('https://discord.com/api/guilds/' + str(server_id) + '/preview', headers=h)
j = json.loads(r.text)
return j['approximate_member_count']
# approximate_presence_count (count of currently online server members)
def get_approximate_presence_count(server_id):
r = requests.get('https://discord.com/api/guilds/' + str(server_id) + '/preview', headers=h)
j = json.loads(r.text)
return j['approximate_presence_count']
# get the text content of the last 10 messages postet to a specific channel/direct message
def get_last_10_messages_from_channel(channel_id):
r = requests.get('https://discord.com/api/v9/channels/' + channel_id + '/messages?limit=10', headers=h)
j = json.loads(r.text)
m = [c['content'] for c in j]
return m