MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / validate_bot_token

Function validate_bot_token

scripts/setup_discord.py:46–67  ·  view source on GitHub ↗

Validate bot token by calling the Discord /users/@me endpoint.

(token: str)

Source from the content-addressed store, hash-verified

44
45
46def validate_bot_token(token: str) -> tuple[bool, str]:
47 """Validate bot token by calling the Discord /users/@me endpoint."""
48 try:
49 response = requests.get(
50 f"{DISCORD_API_BASE}/users/@me",
51 headers={"Authorization": f"Bot {token}"},
52 timeout=10,
53 )
54 if response.status_code == 200:
55 data = response.json()
56 username = data.get("username", "unknown")
57 bot_id = data.get("id", "")
58 return (
59 True,
60 f"Bot: {username}#{data.get('discriminator', '0')} (ID: {bot_id}), Application ID: {bot_id}",
61 )
62 elif response.status_code == 401:
63 return False, "Invalid token (401 Unauthorized)"
64 else:
65 return False, f"Unexpected response: {response.status_code}"
66 except requests.RequestException as e:
67 return False, f"Network error: {e}"
68
69
70def get_application_id(token: str) -> str | None:

Callers 1

mainFunction · 0.70

Calls 1

getMethod · 0.80

Tested by

no test coverage detected