-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscord_api.py
More file actions
26 lines (25 loc) · 1.01 KB
/
discord_api.py
File metadata and controls
26 lines (25 loc) · 1.01 KB
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
import os
import requests
class DiscordAPI:
@staticmethod
def get_user_info(user_id, access_token=None):
"""
Fetch user info from Discord API. This is a placeholder implementation.
If access_token is provided, fetch info for the authenticated user ("me").
"""
if user_id == "me" and access_token:
# Example: Fetch info for the authenticated user
url = "https://discord.com/api/users/@me"
headers = {"Authorization": f"Bearer {access_token}"}
else:
url = f"https://discord.com/api/users/{user_id}"
bot_token = os.getenv("DISCORD_BOT_TOKEN")
headers = {"Authorization": f"Bot {bot_token}"}
try:
resp = requests.get(url, headers=headers, timeout=5)
if resp.status_code == 200:
return resp.json()
else:
return {"id": user_id, "username": "Unknown"}
except Exception:
return {"id": user_id, "username": "Unknown"}