Files
EvoScientist-Multi/EvoScientist/channels/discord/probe.py
T
X-iZhang c5a4d559a2 Refactor test cases for improved readability and consistency
- Added blank lines for better separation of test cases in multiple test files.
- Reformatted event handling in tests for clarity and consistency.
- Ensured consistent use of multi-line formatting for dictionary arguments in event handling.
- Improved assertions and test descriptions for better understanding.
- Updated test cases across various modules including test_stream_state, test_stream_utils, test_summarization, test_thread_selector, test_tool_error_handler, test_tui_widgets, test_ui_runtime, and test_wechat_channel.
2026-03-15 21:12:51 +00:00

36 lines
969 B
Python

"""Discord bot token validation."""
import logging
logger = logging.getLogger(__name__)
async def validate_discord_token(
token: str, proxy: str | None = None
) -> tuple[bool, str]:
"""Validate a Discord bot token via the REST API.
Returns:
Tuple of (is_valid, message).
"""
if not token:
return False, "No token provided"
try:
import httpx
except ImportError:
return False, "httpx not installed"
url = "https://discord.com/api/v10/users/@me"
headers = {"Authorization": f"Bot {token}"}
try:
async with httpx.AsyncClient(proxy=proxy) as client:
resp = await client.get(url, headers=headers, timeout=10)
if resp.status_code == 200:
data = resp.json()
username = data.get("username", "unknown")
return True, f"Bot: {username}"
return False, "Invalid token"
except Exception as e:
return False, f"Error: {e}"