Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get Patreon data based on discord user id
# Campaign ID can be fetched trough the API (List all Campaigns: GET
# access_token can be created on
# For more data, add fields to either fields[member] or fields[user]. All fields are listed on
async def fetch_patreons(self, campaign_id, access_token):
patreons = {}
url = f'{campaign_id}/members'
params = {
'include': 'user',
'fields[user]': 'social_connections'
headers = {'Authorization': f'Bearer {access_token}'}
while True:
async with, params=params, headers=headers) as response:
if response.status != 200:
return None
patreon_data = await response.json()
patreon_members = {}
for patreon_member in patreon_data['data']:
patreon_user_id = patreon_member['relationships']['user']['data']['id']
patreon_members[patreon_user_id] = patreon_member['attributes']
for patreon_user in patreon_data['included']:
if patreon_user.get('type') != 'user':
patreon_user_data = patreon_user['attributes']
if not patreon_user_data.get('social_connections'):
discord_data = patreon_user['attributes']['social_connections']['discord']
if not discord_data:
discord_user_id = int(discord_data['user_id'])
member = patreon_members.get(patreon_user['id'])
if not member:
patreons[discord_user_id] = member
pagination_data = patreon_data['meta']['pagination']
if not pagination_data.get('cursors'):
next_cursor_id = pagination_data['cursors']['next']
params['page[cursor]'] = next_cursor_id
return patreons
# Returns DiscordUserID: PatreonData
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment