Skip to content

Instantly share code, notes, and snippets.

@nathanctech
Created December 1, 2019 05:02
Show Gist options
  • Save nathanctech/fe43e347cf9d3296a75a2438f20c93ed to your computer and use it in GitHub Desktop.
Save nathanctech/fe43e347cf9d3296a75a2438f20c93ed to your computer and use it in GitHub Desktop.
Discord Audit Log Searcher
"""
Discord Audit Log Search
Very simple audit log searching to locate actions against a particular user ID.
"""
import requests
import json
import time
# Bot token, requires "View Audit Log"
token = ""
# guild ID
guild_id = ""
# 100 entries per page, parses ~2 pages per second.
pages = 10
# the user ID to search for in the logs
target_id = ""
# Event to search. See https://discordapp.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events for full reference
event_id = "25" # member role update
url = "https://discordapp.com/api/v6/guilds/" + guild_id + "/audit-logs"
session = requests.Session()
session.headers.update({"Authorization": "Bot " + token})
# first page
request = session.get(url + "?action_type=" + event_id + "&limit=100")
parsed = json.loads(request.text)
# get snowflake of last entry
last = parsed['audit_log_entries'][-1]['id']
# request next page, loop until number of pages requested is reached
page = 2
results = dict()
while page <= pages:
request = session.get(url + "?action_type=" + event_id + "&limit=100&before=" + last)
parsed = json.loads(request.text)
for entry in parsed['audit_log_entries']:
if entry['target_id'] == target_id:
results.update(entry)
print("Found result: " + json.dumps(entry))
print("Page: " + str(page))
page += 1
last = parsed['audit_log_entries'][-1]['id']
time.sleep(0.25)
print("ok")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment